Need change workflow restart with state value to reset

Keerti2
Mega Expert

Hi All, 

Need a background script to restart change workflow , we have modified workflow that has to be attached for existing changes , i tried below background script ,  workflow restarted but all approval were canceled .

i would need to restart workflow with approval state modified to "pending approvals"  ( there were 5 approvals for each change record.

var gr = new GlideRecord('change_request');
if(gr.get("1db76432dba2c3005917572e5e96191b")){
new WorkflowApprovalUtils().cancelAll(gr, 'Cancelling Change ' + gr.getDisplayValue());
new Workflow().restartWorkflow(gr);
}

 

there is yes/no type field in change form , if  we choose 'yes'  type change record has to attach specific workflow ( around 300 changes exist with Yes) ,   If 'no'  type changes  attach another workflow ( 400 no type changes exist)

Kindly help me to apply the same to all changes records... little urgent help plz

 

3 REPLIES 3

Nitin_NOW
Tera Guru

Hello 

Please find the below background script code which might help you to sort the issue. 

Note: Please make the changes according to your business use case. Fyi, here the GlideRecord would be on 'change_request' table.

 

var gr = new GlideRecord('sc_req_item');
gr.addQuery('sys_id', 'IN', 'fd4aa2e20f6d6304fe2342bce1050eed,d286161e0fe52304fe2342bce1050eba,db46121e0fe52304fe2342bce1050e56,2d1656da0fe52304fe2342bce1050ea3');
gr.query();
while (gr.next()){
new Workflow().restartWorkflow(gr, true);
gr.state = "1";
gr.stage = "fulfillment";
gr.active = true;
gr.update();
}

 

Please hit correct based on solution.

Thanks

How about approval , if i ran above BR  approval got cancelled , need to update approval state to "Pending approval" for all change recors

 

Please validate and corrected script for approvals updated to requested

 


var gr = new GlideRecord('sc_req_item');
gr.addQuery('sys_id', 'IN', 'fd4aa2e20f6d6304fe2342bce1050eed,d286161e0fe52304fe2342bce1050eba,db46121e0fe52304fe2342bce1050e56,2d1656da0fe52304fe2342bce1050ea3');
gr.query();
while (gr.next()){
new Workflow().restartWorkflow(gr, true);
gr.state = "1";
gr.stage = "fulfillment";
gr.active = true;
gr.update();
}
var abc = new GlideRecord("sys_approval");
abc.addQuery('approval',fd4aa2e20f6d6304fe2342bce1050eed);
abc.addQuery('approval',cancelled)
abc.query();
while(gr.next()){
current.approval=requested;
}