How to write a lock() function in script include?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2023 12:24 AM
Hey all,
I'd like to write a function that receives the parameter of the current workflow context and locks it, so that other asynchronously running workflows cannot modify the records.
function lock(wfContextRecord) {
// Do I need to set the lock in the wfContext, maybe in "Workflow Executing Activities" or somehow block the record (related Record INC10320) on which the wfContext runs? But how exactly should I lock it using a script?
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2023 02:10 AM
why other workflows will modify the current record?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2023 06:00 AM
There are some workflows that run asynchronously, and there's a risk that they might modify the records. My primary objective is to intervene using a lock() function. That is the requierment what I need to implement..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2023 03:27 AM
Please check which other workflow is changing the overriding the value. You have to make sure no parallel workflow should trigger on one request. If it rusn they should have a different conditions so that both shouldnt interrupt others flow.
Get the show workflow UI action on your request and see how many are trigerring at the same time. If there are multiple workflows then you have to check the condition and if one override other.
In ideal scenario, only one workflow should be running against a single request. All the conditions should be written in one workflow.
Hope it helps.
Regards,
Shamma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2023 06:08 AM
Thank you! I understand that there might be a better solution, but due to the requirements, I'd like to attempt using the lock() function if possible. However, I'm still unsure how to implement it.