Restart Workflow from UI Action

Wade Clairmont
Tera Guru

Seems like a repetition of what is already out there, but I have tried it all and failed.  I am trying to simply restart a workflow, retaining the previous approvals from a UI Action.  Any thoughts on the action shown below?

find_real_file.png

Thanks in advance.

1 ACCEPTED SOLUTION

Wade Clairmont
Tera Guru

After all the hoopla, simple piece of code works like magic!  Delete the current approvals, as the approval history keeps the history for audit, reset your states and delete the current workflow.  When the record is submitted, it just executes the workflow again. Simple.

prepareApprs();

current.approval = 'requested';
current.u_approval_type = 'extend';

var wf = new Workflow();
wf.deleteWorkflow(current);

current.update();

function prepareApprs(){
   var cursys = current.sys_id;
   var manAppr = new GlideRecord('sysapproval_approver');
   manAppr.addQuery('sysapproval.sys_id', cursys);
   manAppr.addQuery('state', 'IN', 'approved,rejected');
   manAppr.query();

while(manAppr.next()){
   manAppr.deleteRecord();
   }
}

View solution in original post

3 REPLIES 3

DirkRedeker
Mega Sage

Hi

I think you call to restartWorkflow should not have the current of the record, the workflow runs on, but on the specific workflow context. 

I guess that's the issue.

 

Or Review the following article :

https://community.servicenow.com/community?id=community_question&sys_id=c18ff2e9db58dbc01dcaf3231f9619c2

 

Maybe, you need to put 'global' as the prefix... 

 

Let me know if that answered your question and mark my answer as correct and helpful, please 

BR 

Dirk 

AbhishekGardade
Giga Sage

Hello wade,

Check out few pointers

1. As you are using server side ui action Below things wont work:

  • Confirm box wont work her 
  • g_form wont work here as your  So simply you can use gs.addInfoMessage();

2. If you want to use both client scide and server side code in single UI ACTION, check out below link:

https://www.servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/  

3. Workflow restarting is fine: check out this for reference:

https://community.servicenow.com/community?id=community_question&sys_id=c18ff2e9db58dbc01dcaf3231f96...

Let me know if you need help in scripting

Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade

 

Thank you,
Abhishek Gardade

Wade Clairmont
Tera Guru

After all the hoopla, simple piece of code works like magic!  Delete the current approvals, as the approval history keeps the history for audit, reset your states and delete the current workflow.  When the record is submitted, it just executes the workflow again. Simple.

prepareApprs();

current.approval = 'requested';
current.u_approval_type = 'extend';

var wf = new Workflow();
wf.deleteWorkflow(current);

current.update();

function prepareApprs(){
   var cursys = current.sys_id;
   var manAppr = new GlideRecord('sysapproval_approver');
   manAppr.addQuery('sysapproval.sys_id', cursys);
   manAppr.addQuery('state', 'IN', 'approved,rejected');
   manAppr.query();

while(manAppr.next()){
   manAppr.deleteRecord();
   }
}