- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2017 12:27 AM
Hi All,
Anyone who has an idea how to reset or restart a workflow with a UI Action? Basically, I have my UI Action made and here is my configuration:
With this script:
function back2Draft() {
//Set the 'State' values to 'Review', and display mandatory fields
g_form.setValue('state',1);
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'demand.back2Draft'); //MUST call the 'Action name' set in this UI Action
}
if (typeof window == 'undefined')
ServerBack2Draft();
function ServerBack2Draft() {
var objctask = new GlideRecord("change_task");
objctask.addQuery('u_demand',current.sys_id);
objctask.query();
while(objctask.next()){
objctask.state = 7;
objctask.update();
new WorkflowApprovalUtils().cancelAll(current, comment);
new Workflow().restartWorkflow(current,false);
current.state = 1;
current.update();
action.setRedirectURL(current);
}
}
The Demand State is not changing and the Change Tasks only Closed Skipped the 1st task.
Many thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2017 01:37 AM
Hi Diane,
Can you see the below code I was updated and added the code to delete task.
cancelWorkflow();
deleteTasks();
current.state = 6;
gs.addInfoMessage('Change ' + current.number + ' has been reset. Any open tasks have been cancelled and the Change will need to go through the Approval process again, if required.');
current.update();
function cancelWorkflow(){
new WorkflowApprovalUtils().cancelAll(current,'Workflow has been restarted, new approval will be needed.');
var wf = new Workflow();
wf.deleteWorkflow(current);
}
function deleteTasks(){
// Delete any running change tasks
var cTask = new GlideRecord('change_task');
cTask.addQuery('change_request',current.sys_id);
cTask.query();
while (cTask.next()){
cTask.deleteRecord();
}
}
}
Please let me know if my comment was helpful and mark it accordingly (like, helpful, correct) so that others can be helped.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2017 12:31 AM
Hi Diane,
See if these links helps you.
Restart Workflow in requested item by UI action
Restart / Reset Request Workflow
Restart CHG Workflow with UI Action

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2017 12:31 AM
Hi Diane,
This below link will help you to find the exact code to restart workflow in UI Action:
Restart Workflow in requested item by UI action
Hope it helps!!
Regards,
Anjali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2017 12:45 AM
Hi Diane,
The below code is helpful for you to restart your workflow. AT that point first you have to cancel your running workflow and again you need to restart.
cancelWorkflow();
function cancelWorkflow(){
// Cancel running workflows.
new WorkflowApprovalUtils().cancelAll(current,'Workflow has been restarted, new approval will be needed.');
var wf = new Workflow();
wf.deleteWorkflow(current);
}
Please let me know if my comment was helpful and mark it accordingly (like, helpful, correct) so that others can be helped.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2017 11:51 PM
Hi All,
Still no progress about in resolving this issue. Do you have an idea on how can I restart the workflow and erase or remove all tasks related to it?
Many thanks!!!