- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2017 04:43 AM
I need some assistance in auto-canceling or closing related CTASK items when the CHG is moved to closed incomplete or canceled state. My current UI Action on the change will close the change request, but the underlying task is remaining open in the fulfiller's work queue. Thoughts?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2017 08:13 PM
HI Cyndi,
You will have to write a Business rule to achieve this
Table : Change_request
Type : After
Insert : true
Update : true
Conditions : current.state == 7 && current.state.changes() // place your values of state accordingly
Script :
abortKids();
function abortKids() {
if (current.sys_id == '')
return;
var kids = new GlideRecord('change_task');
kids.addQuery('parent', current.sys_id);
kids.query();
while (kids.next()) {
if (kids.active == true) {
kids.state = 7;
kids.update();
}
}
}
Note : This can also be achieved using UI action placing the same code. Let me know if you have any issues.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2017 04:57 AM
You can write a script include and call the function in that script include from your UI action
The function would be
function closeCtask(number) // parameter will be the current sys_id of the change which is getting closed Incomplete
{
var gr=new GlideRecord('change_task');
gr.addQuery('change_request',number);
gr.query();
while(gr.next())
{
gr.state=3;
gr.update();
}
}
Please mark the script include client callable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2017 03:53 AM
Thanks Manoj!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2017 10:13 AM
I'm having a heck of a time getting a script include to work for this. Scenario, Change moves to Review, cancel any open tasks. The workflow no longer cancels them because there are more activities added after it changes to Review. I could write the gliderecord but it's not allowed, we must write a script include and call it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2017 05:01 AM
Hi Cyndi
I'm not that great at scripting but you could try a client script like the following:
I basically pops up a confirm box and if they ok it then it will set any open change tasks to Closed Incomplete. You could go for another value depending on what you want.
It also drops an update into the work notes
Client Script
onChange
Field name: state
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (newValue == 3){
var chg_id = g_form.getUniqueValue();
var gr = new GlideRecord('change_task');
gr.addQuery('change_request', chg_id);
gr.addQuery('state', '!=', 3);
gr.addQuery('state', '!=', 4);
gr.addQuery('state', '!=', 7);
gr.query();
if(gr.next()){
var answer = confirm(getMessage ('message to tell them tasks are open'));
if(answer == true){
var ngr = new GlideRecord('change_task');
ngr.addQuery('change_request', chg_id);
ngr.addQuery('state', '!=', 3);
ngr.addQuery('state', '!=', 4);
ngr.addQuery('state', '!=', 7);
ngr.query();
while (ngr.next()){
ngr.state = 4;
ngr.work_notes = 'Autoclosed by parent change';
ngr.update();
}
}
if(answer == false){
g_form.setValue('state', oldValue);
}
}
}
}