How to configure auto close functionality of an interaction Once all associated tasks are closed?

HARI KISHAN GVS
Mega Sage

Hi Team,

i need to build a businessrule on Incident and requested item tables  or on Interaction table to check all the related tasks are closed or not before closing the interaction.

i.e.

1. Create an Interaction.

2. create an Incident from that Interaction.

3. create a request from the same interaction.

4. Close the Incident. Here my Businessrule should check whether remaing tasks in the interaction is closed or not. if closed, close the interaction along with the incident. if not, interaction should stay in work in progress state.

5. Close the request. Here my Businessrule should check whether remaing tasks in the interaction is closed or not. if closed, close the interaction along with the requested item. if not, interaction should stay in work in progress state.

6. Once all related tasks are complete interaction should close automatically.

Note: we can create multiple incidents, requests from a single interaction.

 

my issue building a business rule is, there is no reference field refer to Interaction table is available in Incident and Requested Item Tables. Related Tasks are getting populated in interaction via 'Related Tasks' Relationship. and this relationship is using 'interaction_related_record' table and Interaction and Task tables to pull the related tasks.

i don't have enough experience to build this kind of queries and  script to check these kind of scenarios. 

can anyone please provide the sample script for it.

Thanks in advance.

Hari Kishan.

 

1 ACCEPTED SOLUTION

HARI KISHAN GVS
Mega Sage

Hi Hari,

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

View solution in original post

6 REPLIES 6

@Tuellmom Hello,
Write a scheduled job in case you want to auto-close everyday. If you want to auto-close the previous interaction bulk-records write a fix-script.

MahalakshmiJ
Tera Contributor

Hi Hari, 

I have created a custom state in interaction table. and also I have one UI Action created in service operation workspace. Upon clicking of that UI Action, I want the state to be moved to the custom state created. But for me The OOB business Rule "Interaction - Closed" is overriding that configuration and moving the state to closed complete. I dont want to deactivate that business rule since I am using that. I have gone through the scripts inside the business rule, but i dont see any state setting configurations. Kindly if you have any solutions. Help me out