Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Auto close interactions records

Shanice Mckenzi
ServiceNow Employee

Hello,

 

What is the best way to have interactions records auto-close after the associated incident/request closed? Customer wants to avoid the extra effort to close these manually?

 

#ITSM

3 REPLIES 3

Not applicable

Hi @Shanice Mckenzi ,

it would require two business rules. one is on the Task table and another one on the interaction related record table.

1. create a field called 'Interaction(u_interaction) on the Task table.

2. Create a Business rule on interaction related record table (before insert update)to copy the interaction field to task table.

3. Create a business rule on task table (after update and Active changes to false)to set the interaction to closed complete once all related task are in active false state.

(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);
(function executeRule(current, previous /*null when async*/) {

	var gr = new GlideRecord('task');
	gr.addQuery('sys_id', current.document_id);
	gr.query();
	if(gr.next()){
		gr.u_interaction = current.interaction;
		gr.update();
	}
	var gr1 = new GlideRecord('interaction');
	gr1.addQuery('sys_id', current.interaction);
	gr1.query();
	if(gr1.next()){
		gr1.state = 'work_in_progress';
		gr1.update();
	}
	

})(current, previous);

 

Credits 

Not applicable

Hi @Shanice Mckenzi ,

 

Sandeep Rajput
Tera Patron

@Shanice Mckenzi Best way is to write a business rule on the respective table with a condition state changes to Closed Complete. Query the interaction table to check if an entry for the same task exist within interaction_related_record (Interaction Related Records) already exist, if yes then pic the corresponding Interaction record and set it to close.

 

Screenshot 2024-02-13 at 8.31.04 PM.png