Concurrent record updates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
If a record update process and a reference process are performed at the same time, a problem will occur in the state of the record object in the reference process.
var gr = new GlideRecord('incident');
gr.query();
if (gr.next()) {
~~Various processing~~
// If another process updates the same record here, the value may have changed.
gs.info(gr.short_description); // → May be blank
}
I thought I could use get() to update the state of the record object, but is this an acceptable process?
↓
var gr = new GlideRecord('incident');
gr.query();
if (gr.next()) {
var tmp_sys_id = gr.sys_id;
~~Various processing~~
gr.get(tmp_sys_id);//Update here
gs.info(gr.short_description);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
@bonsai ,
Re calling gr.get(tmp_sys_id) mid processing can refresh the GlideRecord with the latest DB state, but it’s not a robust concurrency control method...... better approaches would involve using GlideRecord.forUpdate(), version / last_updated checks, or optimistic locking to detect conflicts, rather than relying on re getting the record halfway through....
If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
6 hours ago
Are there any APIs such as [forUpdate()] or [last_updated()]?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
yes you are on right track.
when you use get() method it re-fetches the record from the database and you will have the correct value in your script from that field.
💡 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 || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
there is no OOTB method to check last updated timestamp etc
Thank you for marking my response as helpful.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader