.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 11:58 PM
Hello! I think the record is always there, because in the logs I see its correct number req_parent.number, for example "RITM4756385"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2019 12:56 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2019 01:11 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2019 01:13 AM
But the problem is not that I am not getting sys_id, but that the record is not updated by the command
.update()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2019 02:08 AM
Did you check the logs. If the update is failing, then you shall see an error in the error log.