How to write a lock() function in script include?

IgorMK
Tera Contributor

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?
}

IgorMK_0-1697009060482.png

 



4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@IgorMK 

why other workflows will modify the current record?

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

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

Shamma Negi
Kilo Sage
Kilo Sage

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

Regards,Shamma Negi

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.