- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2019 07:59 AM
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?
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2019 08:50 AM
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();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2019 08:10 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2019 09:04 AM
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:
Let me know if you need help in scripting
Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2019 08:50 AM
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();
}
}