- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2015 07:03 AM
I've got a requirement to be able to cancel a workflow at any given time during the time the workflow is active.
I found this thread which gave me more or less all answers on how to do this.
What I need help with is that all open tasks in the workflow should be closed with a specific close note, but the ticket shouldn't get the same close note (it should still be blank).
My current code is as follows
function cancel(){
if(confirm('Are you sure you want to cancel the New Supplier process?')){
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'cancel_new_supplier'); //MUST call the 'Action name' set in this UI Action
return true; //Abort submission
}
return false;
}
// Server side code
if(typeof window == 'undefined')
cancelNewSupplier();
function cancelNewSupplier(){
current.active=false;
current.state=4; //Closed Incomplete
new Workflow().cancel(current);
action.setRedirectURL(current);
current.update();
gs.addInfoMessage('The New Supplier Process has been canceled.');
}
The function cancelNewSupplier() set the same state to all open tasks and the ticket which is OK, but the close code should only go to the open tasks.
How do I achieve this?
I tried with the following code but it only set the close notes for the ticket
current.close_notes='New Supplier Process were canceled by SCM';
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2015 01:00 AM
This works fine, it set everything to the open tasks and no more tasks are being created.
But there is another thing that happened now, or should I say not happen. I do have a script that copy close notes from the task to the ticket and that script isn't executing anymore for the tasks being closed.
I guess I'll just have to make a decision which code to use, either the one you suggested (pasted below) or the one I used before which wasn't optimal (from my post Sep 3, 2015 2:33 PM)
function cancel(){
if(confirm('Are you sure you want to cancel the New Supplier process?')){
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'cancel_new_supplier'); //MUST call the 'Action name' set in this UI Action
return true; //Abort submission
}
return false;
}
// Server side code
if(typeof window == 'undefined')
cancelNewSupplier();
function cancelNewSupplier(){
//Close all active supplier tasks, set work notes and cancel the workflow.
var gr = new GlideRecord('u_supplier_task');
gr.addQuery('parent', current.sys_id);
gr.addEncodedQuery('state!=3^state!=4'); //NOT Closed Complete or Closed Incomplete
gr.addQuery();
gr.query();
while (gr.next()){
gr.close_notes='Arbetsorder har automatiskt stängts när SCM avbrutit flödet för Ny Leverantör';
gr.state = 4; //Closed Incomplete
gr.setWorkflow(false);
gr.update();
}
//Cancel workflow
new Workflow().cancel(current);
current.active=false;
current.state=-7; //Review
current.close_notes='Flödet för Ny Leverantör har avbrutits av SCM, alla icke utförda arbetsorder har automatiskt stängts';
current.update();
action.setRedirectURL(current);
gs.addInfoMessage('The New Supplier Process has been canceled.');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2015 01:00 AM
This works fine, it set everything to the open tasks and no more tasks are being created.
But there is another thing that happened now, or should I say not happen. I do have a script that copy close notes from the task to the ticket and that script isn't executing anymore for the tasks being closed.
I guess I'll just have to make a decision which code to use, either the one you suggested (pasted below) or the one I used before which wasn't optimal (from my post Sep 3, 2015 2:33 PM)
function cancel(){
if(confirm('Are you sure you want to cancel the New Supplier process?')){
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'cancel_new_supplier'); //MUST call the 'Action name' set in this UI Action
return true; //Abort submission
}
return false;
}
// Server side code
if(typeof window == 'undefined')
cancelNewSupplier();
function cancelNewSupplier(){
//Close all active supplier tasks, set work notes and cancel the workflow.
var gr = new GlideRecord('u_supplier_task');
gr.addQuery('parent', current.sys_id);
gr.addEncodedQuery('state!=3^state!=4'); //NOT Closed Complete or Closed Incomplete
gr.addQuery();
gr.query();
while (gr.next()){
gr.close_notes='Arbetsorder har automatiskt stängts när SCM avbrutit flödet för Ny Leverantör';
gr.state = 4; //Closed Incomplete
gr.setWorkflow(false);
gr.update();
}
//Cancel workflow
new Workflow().cancel(current);
current.active=false;
current.state=-7; //Review
current.close_notes='Flödet för Ny Leverantör har avbrutits av SCM, alla icke utförda arbetsorder har automatiskt stängts';
current.update();
action.setRedirectURL(current);
gs.addInfoMessage('The New Supplier Process has been canceled.');
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2015 01:36 AM
Guess you have a business rule for copying the task close notes to the parent request.. Since we are using gr.setWorkflow(false); , it will block the execution of business rules and hence its not getting copied..
But try adding the below lines to the script and see how it goes.
function cancel() {
if (confirm('Are you sure you want to cancel the New Supplier process?')) {
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'cancel_new_supplier'); //MUST call the 'Action name' set in this UI Action
return true; //Abort submission
}
return false;
}
// Server side code
if (typeof window == 'undefined')
cancelNewSupplier();
function cancelNewSupplier() {
//Close all active supplier tasks, set work notes and cancel the workflow.
var gr = new GlideRecord('u_supplier_task');
gr.addQuery('parent', current.sys_id);
gr.addEncodedQuery('state!=3^state!=4'); //NOT Closed Complete or Closed Incomplete
gr.addQuery();
gr.query();
while (gr.next()) {
gr.close_notes = 'Arbetsorder har automatiskt stängts när SCM avbrutit flödet för Ny Leverantör';
gr.state = 4; //Closed Incomplete
gr.setWorkflow(false);
gr.update();
var parentObj = gr.parent.getRefRecord();
parentObj.close_notes = 'Arbetsorder har automatiskt stängts när SCM avbrutit flödet för Ny Leverantör';
parentObj.setWorkflow(false);
parentObj.update();
}
//Cancel workflow
new Workflow().cancel(current);
current.active = false;
current.state = -7; //Review
current.close_notes = 'Flödet för Ny Leverantör har avbrutits av SCM, alla icke utförda arbetsorder har automatiskt stängts';
current.update();
action.setRedirectURL(current);
gs.addInfoMessage('The New Supplier Process has been canceled.');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2015 01:42 AM
It's a business role that copy the close notes from the task to the ticket.
I tried your code but nothing changed.
Well I'm happy with the solution at the moment and will see which one they prefer and if I need to change anything.
Thanks a lot for the help