.update() does not work and returns null
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2019 08:27 AM
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?
- Labels:
-
Field Service Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2019 08:32 AM
Hi,
Did you try adding try catch block for exception handling?
also print last error message while updating. it will tell any business rule which is before update is blocking the update.
try{
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();
var errorMessage = req_parent.getLastErrorMessage();
gs.log('Error Message is: ' + errorMessage);
gs.log("##### For " + req_parent.number + " - success. ID of the updated record: " + req_id);
}
catch(ex){
gs.log('Exception is: ' + ex);
}
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2019 08:36 AM
Yes, I have a similar block.
try {
....
} catch(e) {
gs.log("##### For " + req_parent.number + ' Error ' + e.name + ":" + e.message + "\n" + e.stack);
}
but it does not cause an error - the operation is normally performed, but does not change the record and returns null to me

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2019 12:28 PM
Hi Yuriy,
Can you try using
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
req_parent.update();
var req_id =req_parent.number;
gs.log("##### For " + req_parent.number + " - success. ID of the updated record: " + req_id);
Thanks,
Jaspal Singh
Hit Helpful or Correct onthe impact of response.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2019 02:12 PM