AnsweredAssumed Answered

Why does my Find fail when script is run from Server?

Question asked by user17152 on Sep 12, 2017
Latest reply on Sep 15, 2017 by PeterDoern

I'm just getting my feet wet with running scripts on the server.  I have a scheduled script on FM16 Server that is supposed to go through my solution's Events table and verify that the contents of an unstored calculation match the contents of a stored, indexed field.  These stored fields are filter fields used both by my UI and the SoSimple Calendar.

 

An example is project status.  Every event belongs to a project and every project has a status.  When the project status is changed (pop-up menu), a script trigger runs that updates every event record for the project with the new status.  The Events table contains several pairs of filter fields.  The first field is an unstored calculation.  The second field is the stored data.  These fields should always be in sync if the UI is behaving as expected.  The filter fields are always updated via the UI when the user does something (ie: change project status, assign/remove a user from a project, etc) and the calculation is how I check to make sure they are in sync.

 

The scheduled script I am asking about will run every evening and verify that the calc / stored filter fields in the Events table match.  Hopefully it never finds a problem, but if it does, I will know which Event is out of sync and be able to troubleshoot.

 

So here's my question.  I created a calculated field in the Events table called Events::Out_Of_Sync.  The field is unstored and the calculation looks like this:

 

Case (

    Event::Project_Status_Stored ≠ Event::Project_Status_Calc ; 1 ;

    Event::Project_User_List_Stored ≠ Event::Project_User_List_Calc ; 1 ;

    0

)

 

The script executes a Perform Find on this field looking for a value of 1 (out of sync).  If it finds any out of sync records, it loops through them and syncs the various fields, logging the Event ID and what was out of sync.

 

The script works perfectly when I run it from a client.  However, when run from the server as a scheduled script, it incorrectly finds approximately 2/3 of my events to be out of sync.

 

So I changed my script and took out the Perform Find.  Now my script goes to the Events table, shows all records, loops through them and evaluates each with an If statement:

 

If [

     Case (

          Event::Project_Status_Stored ≠ Event::Project_Status_Calc ; 1 ;

          Event::Project_User_List_Stored ≠ Event::Project_User_List_Calc ; 1 ;

          0

     )

]

 

If true, the record is out of sync and the sync action is performed.  If not, the script continue and goes to the next record.

 

This works fine.  What is it about the Find that is failing on the server?  I'm happy it works by looping through the entire table, but I'd like to understand why my first approach didn't work.  Thanks!

Outcomes