How to re-start workflow (change request) after approval rejection

rhofing
Tera Contributor

We have a change workflow that starts with a Change in Draft state.   When the user is ready they submit it to be validated (state = To be Validated). The validator then moves the change to Requested state which sends notification to the approvers.   It can then be approved or rejected.   If approved it moves on until the end. This is working fine.

However, if it is rejected a notification is sent to the requester (this works fine), but I want to reset the state to Draft (so the requester can re-work the Change and then re-submit to validation), which I did with a script, and then re-start the work flow.   This is not working.   I tried using rollback back the workflow kicks in immediately and places the change in the To Validate state. Essentially what I want to do is start completely over with the existing change request.

Thank you!

Ric

6 REPLIES 6

Ken83
Mega Guru

I use this function to restart my workflow...



startWorkflow(current.cat_item.workflow); // assuming this is on the item level. In your case, you would use the sys_id of the workflow you want to restart.


action.setRedirectURL(current);




function startWorkflow(id) {


  var w = new Workflow();


  var context = w.startFlow(id, current, current.operation('update'), getVars());


  if (context != null)


  current.context = context.sys_id;


}




/**


* Get the variables from the request item so that we can map these to the workflow.input


* variables if the names match.


*/


function getVars() {


  var vars = {};


  for (var n in current.variables)


  vars[n] = current.variables[n];



  return vars;


}


Hi Kenneth,


I found your code to refresh an Item workflow .It's working fine.


But can you tell me how to refresh a request workflow?


restartWorkflow(current,false); // the true or false flag will determine if you want to leave existing approvals in their current state. I'm assuming not, so it's false    


action.setRedirectURL(current);  


 


 


function restartWorkflow(current, flag) {  


  var w = new Workflow();  


  var context = w.restartWorkflow(current,flag);    


}  



This is from the hip, but I believe it'll work for what you need. Just make sure you're using it in a UI Action or Business Rule on the Request(sc_request) level if you're trying to restart the request workflow.


cfam1
Mega Expert

I build into the original Change workflow.   Not only a rollback but also add a set values to set the values in the Change to Draft or whatever (you can set the approval field as well), then a switch to control when it actually fires the rollback.   If the Requestor decides to cancel, the workflow cancels and no additional approvals are sent, if they resubmit (let's say the approver wanted more information), it then rollsback for the approvals.



find_real_file.png