- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
14 hours ago
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
HI @suryaogeti1 ,
1.The configuration should be like this , add filter conditions as per requirement
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);- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
13 hours ago - last edited 13 hours ago
Hi @suryaogeti1 ,
Try this
// Business Rule After update on Incident table
// When Incident is closed, close associated Interaction
(function executeRule(current, previous /*null when async*/) {
// Check if Incident is moving to Closed
if (current.state == 7 && previous.state != 7) { // 7 = Closed
// Get the associated Interaction record
var interactionId = current.u_interaction; // assuming you have a reference field
if (interactionId) {
var interactionGR = new GlideRecord('interaction'); // table name may be 'interaction' or custom
if (interactionGR.get(interactionId)) {
interactionGR.state = 7; // set to Closed
interactionGR.update();
}
}
}
})(current, previous);
Thanks,
BB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
13 hours ago
Hi @suryaogeti1 ,
1.Create a After Update business rule on incident.
2.Use the following script
(function executeRule(current, previous /*null when async*/) {
var gr=new GlideRecord("interaction_related_record");
gr.addQuery("document_table","incident");
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12 hours ago
Hi @Rakesh_M
can we create additional field named 'interaction' in the incident form or how the code will check the associated record is present or not in the incident form. how it will read the associated interaction record. please elaborate if possible or give me the guidance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11 hours ago
Hi @suryaogeti1 ,
- When an Incident is created from an Interaction, a record is automatically created in the interaction_related_record table.
- This table acts as a bridge between the Interaction and related records like Incident, Request, or Change.
- The relationship is maintained using key fields:
- Interaction → reference to the Interaction record
- Document Table → the table name of related record(e.g., Incident)
- Document ID → the specific record (e.g., current Incident )
so we use this record to find the interaction record that needs to be closed when incident is resolved/closed
- In the script:
var gr=new GlideRecord("interaction_related_record"); //
gr.addQuery("document_table","incident");
gr.addQuery("document_id",current.sys_id);
gr.query();​- We query the interaction_related_record table using:
- document_table = incident
- document_id = current.sys_id (the current Incident sys_id)
- Executes the query and retrieves matching records from the table.
- This gives the record that connects interaction and incident
if(gr.next()) //if record is found enter if
{
var interaction=new GlideRecord("interaction");
if(interaction.get(gr.getValue("interaction")))
{
interaction.state="closed_complete";
interaction.update();
}
}​- If a matching record is found, then we move further else script ends here as every incident resolved/closed is not created from a interaction
- now "gr" contains all the details of interaction_related_record
- now we query interaction table and find interaction record then update it's state.
- the above script is equivalent to following script:
if (gr.next()) {
var interaction_sysID = gr.getValue("interaction"); // gets sys_id of interaction
var interaction = new GlideRecord("interaction");
interaction.addQuery("sys_id", interaction_sysID);
interaction.query();
if (interaction.next()) {
interaction.state = "closed_complete";
interaction.update();
}
}So, we do not need to create an additional field on the Incident form. The association is already maintained through the interaction_related_record table, and the script uses this relationship to find and update the corresponding Interaction.
