The CreatorCon Call for Content is officially open! Get started here.

Concurrent record updates

bonsai
Mega Sage

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); 
}

 

 

 

 

 

4 REPLIES 4

kaushal_snow
Mega Sage

@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.

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/

Are there any APIs such as [forUpdate()] or [last_updated()]?

Ankur Bawiskar
Tera Patron
Tera Patron

@bonsai 

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! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@bonsai 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader