[4.2] - Running another object script trigger on "Valid

Posted by IramK on 18-Aug-2016 08:19

Hello,

I have an object script trigger that sets the date/time value of a date/time field of another (id:12345) record. This trigger is being called from a "Validate Record Data" trigger for the record being created. However when trying to do so, the rbv_api.setFieldValue(...) fails to set the field value for the date/time fields. Could you please let me know when this would be fixed?


Validate Record Data trigger:

var nameValue = "{!name#text}"; 
if(nameValue !== ""){
rbv_api.runTrigger("object1", 12345, "setDateValue", true);
return 'Name cannot be empty'; }

Object Script Trigger:

var currentDate = rbv_api.getCurrentDate(); var value = new Date(); rbv_api.setFieldValue("object1", {!id}, "dateTimeField", value);

Cheers.

Iram 

All Replies

Posted by Nitin Kumar Singh on 19-Aug-2016 04:09

Hi IramK,

When creating/updating records from UI pages, Validation Triggers do not have transaction context set, they are evaluated only to check for validation failure. As such, your 'setDateValue' trigger is being called and executed but changes not persisted.

Thanks,

Nitin

Posted by IramK on 19-Aug-2016 05:17

Hello [mention:e5d6fd9a1d9042a6a3c7b20e0f22c213:e9ed411860ed4f2ba0265705b8793d05] ,

Thanks for your answer. My changes are not persisted only for the date/time field, however they are being updated for other fields like text field or a checkbox field. So my question really is: What exactly is the correct behavior? Should it update or not?

Cheers.

Iram

Posted by Nitin Kumar Singh on 19-Aug-2016 06:57

Hi Iram,

I included code in my 'setDateValue' object script trigger to also update text and boolean fields along-with date/time field. I noticed none of the three fields get updated.

Is this what you meant?

Do you also have code to update date/time, text, boolean fields inside single object script but only notice text/boolean fields getting updated?

Nitin

Posted by IramK on 19-Aug-2016 07:10

Hello [mention:e5d6fd9a1d9042a6a3c7b20e0f22c213:e9ed411860ed4f2ba0265705b8793d05] ,

Yep I have code to update date/time, text and boolean fields inside single object script but only text/boolean fields get updated and not the date/time. What might be the reason?

Also something really strange: Although the date/time field is not updated, but if I go in the object definition and modify any property of any field and save. The date/time field value is visible. Really weird!

Iram

Posted by Nitin Kumar Singh on 23-Aug-2016 03:54

Hi Iram,

We do not have transaction context for validation triggers. So, updates from inside validation triggers will not persist to database, validation triggers can only update them in-memory. Few values that you are seeing being updated could have been picked from memory by some other transaction initiated immediately after validations, and persisting in database as part of their normal update process. However, in memory changes are perishable and not reliable.

Please consider using validation triggers only for simple checks involving select queries and not actual update scripts.

Thanks,

Nitin

Posted by IramK on 29-Mar-2017 04:42

So, this isn't a bug with Rollbase and RB is behaving as expected if I understand this correctly?

Iram

This thread is closed