How to restart a workflow on field change?

Snow Tomcal
Tera Expert

Hi,

I'm trying to restart the change request's workflow on a field change with advanced business rule.

The workflow first activity changes to grey (restarted) and start running again but it is not asking for approvals again (the rest of the workflow stays the same, I checked the workflow history so I know it is restarting),

the script:

(function executeRule(current, previous /*null when async*/){

var chng = new GlideRecord('chnage_request');

chng.addQuery('number', current.number);

chng.query();

 

if(chng.next()){

var workflow = new global.Workflow();

workflow.cancel(chng);

workflow.restartWorkflow(chng);

}

})(current, previous);

 

Anyone have any ideas? Thanks! 🙂

8 REPLIES 8

Mahendra RC
Mega Sage

Hello Snow Tomcal,

Could you please check once with below script:

(function executeRule(current, previous /*null when async*/){
var chng = new GlideRecord('change_request');
chng.addQuery('number', current.number);
chng.query();

if(chng.next()){
var workflow = new global.Workflow();
workflow.cancel(chng);
workflow.restartWorkflow(chng, false);
}
})(current, previous);

Please mark my respsone as helpful/correct, if it answer your question.

Thanks

It is still restarting the workflow without asking for the approvals again.

Vaishnavi Lathk
Mega Sage
Mega Sage

Hello,

(function executeRule(current, previous /*null when async*/){
var chng = new GlideRecord('change_request');
chng.addQuery('number', current.number);
chng.query();

if(chng.next()){
var workflow = new global.Workflow();
workflow.cancel(chng);
workflow.restartWorkflow(chng, false);
}
})(current, previous);

Refer below blog for more:- 

https://servicenowguru.com/scripting/business-rules-scripting/reset-change-request-workflow-approvals-tasks/

 

Regards,

Vaishnavi

Hi, it is restarting the workflow but only the first core activity changes the color to grey.

The approvals are cancelled but not restarted (it is not possible to approve again).