Best way to Control (delay) selected Scripts On Load
UPDATE: I had posted the topic below the stars earlier and now found a better solution. It was simple, really: For the key fields that need to load "first", create a "partner" field that is filled upon load with the same value as the key fields. Then use key field On Update script conditional on key=partner to trigger the filling of the other lesser fields that needed to be filled "later" . Then add partner="" to the On Update scripts for the lesser fields.
********************************************************************
A cascade of Field Actions were creating inconsistent results when loading a form which would set the values of these fields from data in another form and thus trigger the Field Action during the load process. Triggering those Field Action during load would at the same time update values in the loading form as the result of those Field Actions. The order and timing of the Field Action triggers was creating inconsistent results on load. Below was my solution, but being an amateur, I was wondering if I went about this solution the best way?
- Set the On Load value of a field named LoadTime to zoho current time by putting the script below in the first line of the On Add On Load script.
input.LoadTime = zoho.currenttime;
- Set the value of a field named TimeSinceLoad to the time lapsed since the zoho system started running the On Add On Load script by putting the script below in the last line of the On Add On Load script.
input.TimeSinceLoad = (zoho.currenttime - input.LoadTime);
- Finally, in each Field Action for fields whose values are set at Load and whose Field Action I wanted delayed until the Field Actions of other fields could complete, I conditioned the action by the wait time shown in the script below:
if ((zoho.currenttime - input.LoadTime) > 7000)
{
//various set variable statements inserted here
}
I really do not know what the number generated by the (zoho.currenttime - input.LoadTime) expression means. I could see that it fluctuated from between 28 and 68. I chose the number 7000 in my conditional statement through trial and error, finding a balance between the need to assure non-interference with a complete load of the form and and the need to let the user edit fields in a reasonably soon time after load.
I hope there are some expert users who can suggest better ways to solve this problem or perhaps avoid the problem in the first place.