Process Definition depends upon Calculated Fields, but they are not populated yet (via api)?

Any help with this will be appreciated, as always...  the effect is the same in a few different places so this explanation is generic.

  • New record created via API from our website (new printer registration record (registration custom module))
  • The new record criteria kick starts Process Definition. 
  • The process definition depends upon a calculated field to decide which route to take at a later part of it.
  • However, it seems that at the point of record creation that the calculated field is not yet actually populated.
    • If I do an edit / save or recalculate values within the record itself then the calculated field populates perfectly.   

What I am doing is:

  • Calculating the days from shipping the printer to the date of purchase submitted in the registration web form on our support site.

Below is a screen shot of the fields in question.

note empty 'printer shipped from the factory on' date field.  This the trouble maker here.  Its simply a calculated formula: related($s_serialnumber_g_registration_1,"dateshipped")
But from api created records fails to run.

And after me clicking Edit > Save on the record:

The shipped date is populated and therefore my calculation of the days from shipping to Purchase is accurate - this is the field I later rely upon in the process.

Note - If I create a new registration record just from the create button in the module the fields calculate fine.


So I am wondering....

Q1 - is there a difference between API creation and creating inside sugar modules manually.  (I am not the Dev, I am the Admin)
Is there something else which can be added via the api to get the calculated fields to populate? 

Q2 - Is there a way to force something like a recalculate values from inside my process definition?  Then carry on with the rest of it.

I tried:
 - to populate some random unrequired for anything else field at the start of the Process Definition to see if that had an effect like recalc / edit&save - which it did not.
 - adding a 'wait' event for 1 minute...  but that may be snake oil.  Therefore a 'get message event' will probably be waiting forever too...

Hope that makes sense!
Many thanks...
Luke.

Parents
  • In my experience calculated fields are updated when someone opens the record in the UI. Does the field that is retrieved from the relationship exist at the moment the custom record is created? If so you could adjust the api calls to first retrieve that specific date and set it yourself in the calculated field. Sugar doesn't actually check if it's calculated. When someone opens the record in the UI it will recalc it anyway.

  • Thanks ,   Aha.. I think that sounds like the way to go.   The API (I believe) already brings in a bunch of serial number fields and if the date shipped is one of them then populating the field there would mean the calculation of days from shipping to purchase would be there immediately.  

    I didnt think about populating it there - I will add an update here when we have done this - hopefully it helps other folk too.

    Thanks for the suggestion :-)

     thanks too.  That relationship is there, that is just a calculated formula field to bring the fields data into this modules record.   If a record is created manually (in the UI as Jeroen mentions) then then it all works instantly.   

Reply
  • Thanks ,   Aha.. I think that sounds like the way to go.   The API (I believe) already brings in a bunch of serial number fields and if the date shipped is one of them then populating the field there would mean the calculation of days from shipping to purchase would be there immediately.  

    I didnt think about populating it there - I will add an update here when we have done this - hopefully it helps other folk too.

    Thanks for the suggestion :-)

     thanks too.  That relationship is there, that is just a calculated formula field to bring the fields data into this modules record.   If a record is created manually (in the UI as Jeroen mentions) then then it all works instantly.   

Children