Auto close the interaction record when the associated inc/req is closed

suryaogeti1
Tera Contributor

we have a requirement, when the incident or request is closed, automatically the interaction record needs to close. Already we have a Ui button in SOW interaction form, when we click the button in the interaction form, the incident or request will create. here in incident the associated interaction record is updating in the work notes. now the client wants additional changes which i mentioned in the first line. how can we achieve, please help with the process and the script. 
Thanks in advance

1 ACCEPTED SOLUTION

HI @suryaogeti1 ,
1.The configuration should be like this , add filter conditions as per requirement
Screenshot 2026-04-15 at 9.55.16 PM.png

2.Script:

(function executeRule(current, previous /*null when async*/) {

	var gr=new GlideRecord("interaction_related_record");
	gr.addQuery("document_table","sc_request");  //updated table name
	gr.addQuery("document_id",current.sys_id);
	gr.query();


	if(gr.next())
	{
		var interaction=new GlideRecord("interaction");
		if(interaction.get(gr.getValue("interaction")))
		{
			interaction.state="closed_complete";
			interaction.update();
		}
		
	}


})(current, previous);



View solution in original post

11 REPLIES 11

Hi @Rakesh_M 
will it work for both incident and request right..

Hi @suryaogeti1 ,
It will work only for incident if you want same for request create a BR on request table and change table name in script from incident to sc_request

I found an alternative approach where a interaction is closed immediately after creating a incident/request from interaction
refer:https://www.servicenow.com/community/itsm-forum/interaction-to-be-automatically-closed-when-it-gets-...

Hi @suryaogeti1 ,
It only works for incident,For request you need to create another BR and update the table name in the script.

Hi @Rakesh_M 
Need to change only table name right, rest all will be same 
thank you

HI @suryaogeti1 ,
1.The configuration should be like this , add filter conditions as per requirement
Screenshot 2026-04-15 at 9.55.16 PM.png

2.Script:

(function executeRule(current, previous /*null when async*/) {

	var gr=new GlideRecord("interaction_related_record");
	gr.addQuery("document_table","sc_request");  //updated table name
	gr.addQuery("document_id",current.sys_id);
	gr.query();


	if(gr.next())
	{
		var interaction=new GlideRecord("interaction");
		if(interaction.get(gr.getValue("interaction")))
		{
			interaction.state="closed_complete";
			interaction.update();
		}
		
	}


})(current, previous);