using below script i need to update ritm closer comments
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
i am using below script to update closer comments in ritm but it's inserting the dummy record not updating record
var grval = new GlideRecord('sc_req_item');
grval.addQuery('sys_id','e03fae4b477eb6189c5e5cbd436d439e');
grval.query();
grval.close_notes = 'test';
grval.update();
Any idea on this please let me know
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
may i know why below script is not working
var grval = new GlideRecord('sc_req_item');
grval.addQuery('sys_id', input.ritm_sys_id + '');
grval.close_notes = input.comments;
grval.update();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
the reason it's not working is you are querying but not going to the actual record with next() method
update() method will create a dummy record if it's used directly
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
you should first check if record is present or not
var grval = new GlideRecord('sc_req_item');
grval.addQuery('sys_id', 'e03fae4b477eb6189c5e5cbd436d439e');
grval.query();
if (grval.next()) {
grval.close_notes = 'test';
grval.update();
}
OR
var grval = new GlideRecord('sc_req_item');
if (grval.get('e03fae4b477eb6189c5e5cbd436d439e')) {
grval.close_notes = 'test';
grval.update();
}
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader

