- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2026 10:48 PM
Hi @mani55
The issue with your script is that you are calling grval.close_notes = 'test'; and grval.update(); before checking if the record actually exists. If the query does not return any record, then grval.update() will create a new record instead of updating an existing one.
You need to check if the record was found by using grval.next() before updating the field and calling update().
Here is the corrected version of your script:
var grval = new GlideRecord('sc_req_item');
grval.addQuery('sys_id', 'e03fae4b477eb6189c5e5cbd436d439e');
grval.query();
if (grval.next()) {
grval.close_notes = 'test';
grval.update();
} else {
gs.info('Record not found');
}
Explanation:
grval.query() runs the query.
grval.next() moves the pointer to the first record found (if any).
Only if a record is found, you update the field and call update().
If no record is found, you can log or handle that case accordingly.
This will ensure you update the existing record instead of inserting a new one.