How to update Workflow version of existing records with skipping approval and task creation activities?

mpaskov
Tera Contributor

Hello,

I have a number of ritms with workflow which is in faulty state. I have created a newer version of the workflow which works just fine. How do I update ritms workflow version(in faulty state) with skipping the approval activity as well as task creation activity?

2 REPLIES 2

suvro
Mega Sage
Mega Sage

That is not possible as instance of old workflow is running. Cancel all those contexts and resubmit the form to trigger the updated workflow

Community Alums
Not applicable

Hi @mpaskov ,

Refer to this thread for explanation :https://community.servicenow.com/community?id=community_question&sys_id=b29ac32ddb5cdbc01dcaf3231f96...

You can run a Background script something like this, but this works for one record:

var gr = new GlideRecord("sc_req_item");
gr.addQuery("sys_id", "6eea0285db419c10053830cf9d9634d4");
gr.query();
if (gr.next()) {

new WorkflowApprovalUtils().cancel(gr);
new Workflow().startFlow(new Workflow().getWorkflowFromName('myWorkflowName'), gr, '');
}

Also, 

You can run the glide query inside a for loop. Please see the example below:

var sysIDs = "sys_id_0,sys_id_1,sys_id_2";

// Convert the above string into an array
var arr = sysIDs.split(',');

for (var i = 0; i < arr.length; i++) {
    var gr = new GlideRecord("sc_req_item");
    gr.addQuery("sys_id", arr[i].toString());
    gr.query();
    if (gr.next()) {
        new WorkflowApprovalUtils().cancel(gr);
        new Workflow().startFlow(new Workflow().getWorkflowFromName("<Name of the Workflow>"), gr, '');
    }
}

 

Mark my answer correct & Helpful, if Applicable.

Thanks,

Sandeep