.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

Hello! I think the record is always there, because in the logs I see its correct number req_parent.number, for example "RITM4756385"

Since you are calling update on the existing record, the sys_id of the record does not change. In this case, ou can access the sys_id of your request directly by accessing req_parent.sys_id instead of req_id.

Existing or not, the update function returns null if the update is not successful (according to the system documentation).
That is the only information we care about.


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

Yuriy7
Kilo Contributor

But the problem is not that I am not getting sys_id, but that the record is not updated by the command

.update()

 

Did you check the logs. If the update is failing, then you shall see an error in the error log.