Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Reopen cancelled request

rev3
Mega Expert

How to reopen cancelled Request.

I am changing request state and stage and setting the workflow to true using the below script:

var gr= new GlideRecord('sc_request')

gr.addQuery('sys_id', 'sample sys_id');

gr.query();

while(gr.next()) {

gr.request_state="pending";

gr.setWorkflow(true);

gr.update();

}

But the workflow is not setting back. Is there a way to run the workflow again.

Thank You

1 ACCEPTED SOLUTION

Rather than gr.sys_id, it expects the GlideRecord object.



var gr= new GlideRecord('sc_request')


gr.addQuery('sys_id', 'sample sys_id');


gr.query();


while(gr.next()) {


        gr.request_state="pending";


  new WorkflowApprovalUtils().cancelAll(gr, "comment");


  new Workflow().restartWorkflow(gr, true);


        gr.update();



}


View solution in original post

10 REPLIES 10

Chandu Telu
Tera Guru

HI rev,


    // The following options are available for resetting the approvals:


          //


          // 1. Mark all existing approvals for the change as 'cancelled' and


restart the workflow to create new approvals


          //             new WorkflowApprovalUtils().cancelAll(current, comment);


          //             new Workflow().restartWorkflow(current);


          //


          // 2. Delete all of the existing approvals for the change and restart


the workflow to create new approvals


          new WorkflowApprovalUtils().reset(current, comment);


          gs.addInfoMessage('Workflow has been reset since key fields have been


modified');


          //


          // 3. Leave the approvals for the change in their current state and


restart the workflow.


          //       (so that any new approvals that are required will be created)


          //             if (comment)


          //                   current.setDisplayValue('approval_history', comment);


          //             new Workflow().restartWorkflow(current, true);


          //



    }


}