- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2019 03:59 AM
Hi
I need to write a script that is executed whenever a record is inserted into my "main" table. Based on some criteria the user has selected in the form I need to
- Query a "counters" table
- Increment the counter value
- Update the counters table with the new maximum value
- Use the counter value in the record I'm inserting
All of the above I'm OK with. What I want to know is; how do I lock the row in the counters table to prevent another user from performing the same update at the same time and getting the same counter value as me?
In pure SQL terms I would use a "select for update" on my counter table to lock the row. But I have been unable to find an analogous gliderecord method to do something similar.
I could create a workflow and use a workflow lock, but this seems like overkill for something I should be able to do in a single small script.
Anyone have any suggestions?
Regards
David
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2019 09:59 PM
Hi David,
If you are saying that single field only 1 user should update.
What if 2 users sessions are running and 2 BRs run at same time both the user session will try to update that field
This way you cannot lock that field I believe so.
Try using workflow lock script once.
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2019 09:59 PM
Hi David,
If you are saying that single field only 1 user should update.
What if 2 users sessions are running and 2 BRs run at same time both the user session will try to update that field
This way you cannot lock that field I believe so.
Try using workflow lock script once.
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2019 09:21 AM
Thanks for your reply.
I have proceeded down the workflow route using a workflow lock to ensure only one user at a time updates the record. It seems a bit of a "sledgehammer to crack a nut", but if that's the accepted way to do it, who am I to argue.
Regards
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2019 09:42 AM
Hi David,
We don't know whether that's the only way to do that because this solution would incur extra performance impact on the instance since for every record a workflow context will run
May be you can check with ServiceNow team on better approach
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
