How to stop workflow from executing automatically if there is a error at particular stage ?

Meetk
Tera Contributor

I have designed custom workflow that send GET request to Jenkins at multiple stage. how can i stop the execution of rest workflow if there is error at previous stage. #workflow #flow

1 ACCEPTED SOLUTION

you can cancel the current workflow context using script.

Sample script is available in docs

var grContext = new GlideRecord("wf_context"); 
grContext.get(context_sys_id); 

var grReq = new GlideRecord("sc_req_item"); // add your table on which the workflow is built
 
// The current record may not exist, make sure it exists before modifying it.
if (grReq.get(grContext.id)) {
    grReq.comments = "The workflow has been cancelled due to error in API.";
    grReq.update();
}
Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can check the API response and based on success or failure you can take the output to End activity.

Use if activity to check API response -> Is success?

output of yes -> other activity

output of no -> End activity

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

Meetk
Tera Contributor

Hi Ankur, Thank you for quick response.

i had thought of this however since the workflow is very huge and at each stage Jenkins is called so pointing to end with each stage will make workflow design more complex. if there any way such that if there is error workflow should stop at that point. 

you can cancel the current workflow context using script.

Sample script is available in docs

var grContext = new GlideRecord("wf_context"); 
grContext.get(context_sys_id); 

var grReq = new GlideRecord("sc_req_item"); // add your table on which the workflow is built
 
// The current record may not exist, make sure it exists before modifying it.
if (grReq.get(grContext.id)) {
    grReq.comments = "The workflow has been cancelled due to error in API.";
    grReq.update();
}
Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Meetk
Tera Contributor

Thank you Ankur😀