.update() does not work and returns null

Yuriy7
Kilo Contributor

Often fails to update the record fields

var req_parent = new GlideRecord('sc_req_item');

req_parent.get(current.request_item.sys_id)

req_parent.state = 3;

// then I try to update the record

var req_id = req_parent.update();

gs.log("##### For " + req_parent.number + " - success. ID of the updated record: " + req_id);

This code does not work in a small number of cases (maybe 1-5%)

In the log, I see this message:

"##### For RITM4756385 - success.  ID of the updated record: null"

Although in most cases I see the return value here - the sys_id of records.

Who faced something similar? What diagnostics can be done to identify the cause?

20 REPLIES 20

Yuriy7
Kilo Contributor

I tried to look at errors in the Log Entry table (syslog). At the moment when the function returned null to me, there is nothing suspicious in the logs. I think if there was an error, it would fall into the code try - catch

is the error always random or were you able to replicate with any specific criteria?

Yuriy7
Kilo Contributor

I did not find any relationship to the occurrence of this error. And I could not artificially repeat it.
I think this error depends on some external factors - server overload or something else like that.
It is possible that two actions are performed on the record at the same time (for example, the employee updates the form and my script is working at the same time.) But this version also cannot explain all cases of an error.

My point is this

find_real_file.png

If a sys_id is being returned, then the update was successful. The sys_updated timestamp should have changed to the current. If the update fails, the state should not change and it should return null. 

If the records aren't returning null but the state is not 3, then the value of state must be modified by either users or another business rule.


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

It is not entirely clear what the "update files" means. When can a recording not update?

If the entry was not found, an error would occur here.
I am inclined to such a version that prevents another business rule from updating or a user’s parallel action on this record.
But if the user's action is unpredictable, then we can most likely fix the drawdown of another business rule.
How can I find out what other business rules worked?