Auto Cancel Change Task when Change Request transitioned to Closed Incomplete

cjones3
Tera Contributor

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?

1 ACCEPTED SOLUTION

Aakash Shah4
Tera Guru

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.


View solution in original post

12 REPLIES 12

Manoj Kumar16
Giga Guru

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.


Thanks Manoj!


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.


scott barnard1
Kilo Sage

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);


}



}



}



}