Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Incident and interaction closure

Nawal
Mega Guru

Hello

I have an issue, when I close an incident, the interaction related to that incident does not close, where do I check this please.

 

 

 

1 ACCEPTED SOLUTION

Ok,

 

Then the BR is on Incident table. After - Update

Condition: incident is closed

Script:

ar gr = new GlideRecord('interaction'); //check table name
gr.addQuery('sys_id', current.u_interaction);
gr.addQuery('active', true);
gr.query();
while(gr.next())  //if there is only 1 interaction, you can use if instead of while
{
gr.state = 3; //check closure state value
gr.comments = 'Interaction Closed'; //optional
gr.update();
}
-Anurag

View solution in original post

10 REPLIES 10

Nawal
Mega Guru

Hello Anurag,

thank you for your help,

you script works.

 

I tried this with my collegue and it works too:

(function executeRule(current, previous /*null when async*/) {
      var result = [];
      var array = [];
      var ref = [7,3];
      var gr = new GlideRecord ('task');
          gr.addQuery('u_interaction',current.u_interaction);
          gr.query();


   while (gr.next())
   {
        array.push(gr.state);
   }
   if(array.length > 0)
   {
       for(var i=0;i<array.length;i++)
   {

   var arrayUtil = new ArrayUtil();
      if(arrayUtil.indexOf(ref, array[i])==-1)
    {
          result.push(array[i]);
    }
     }
   }
       if(result.length == 0)
   {
       var inter = new GlideRecord ('interaction');
            inter.addQuery('sys_id',current.u_interaction);
            inter.query();

      if(inter.next())
   {
   inter.state='closed_complete';
    inter.update();
 }
 }
 })(current, previous);