Need change workflow restart with state value to reset
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2019 08:01 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2019 08:25 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2019 08:32 AM
How about approval , if i ran above BR approval got cancelled , need to update approval state to "Pending approval" for all change recors
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2019 10:37 AM
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;
}