- 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-23-2017 12:02 AM
Hi Diane,
Create Ui action and give action name and paste this below code in your action and test this .
cancelWorkflow();
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);
}
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-23-2017 12:49 AM
Hi Pavan,
Thank you so much for this code. Your code didn't remove the tasks related to my Demand. I added a few lines of code and it worked now! Many thanks for your help!!
cancelWorkflow();
current.state = 1;
gs.addInfoMessage('Demand ' + current.number + ' has been set to Draft. Any open tasks have been Closed Skipped and the Demand 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);
}
var objctask = new GlideRecord("change_task");
objctask.addQuery('u_demand',current.sys_id);
objctask.query();
while(objctask.next()){
objctask.state = 7;
objctask.work_notes = "Demand was set to Draft, setting this CTASK to Closed Skipped";
objctask.update();
}
action.setRedirectURL(current);
- 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.