How to close the state of interaction record when the RITM of related REQ is closed

Yakshitha
Tera Contributor

I have a requirement to update the state of interaction record to Closed Complete when the RITM of related REQ is state changes to "Closed Complete" and interaction record to Closed Abandoned when the RITM of related REQ is state changes to "Closed InComplete" or "Closed Skipped".
The issue is I have written a after BR to achieve this but the interaction state is always getting updated as "closed complete" because when the state of SCTASK is changes to "Closed Incomplete" or "closed Skipped" the state of related RITM first changes to "Closed Complete" then immediately changes to "Closed Skipped"/"Closed Incomplete"
So my BR is taking the initial state "Closed Complete" and updates the interaction state "Closed Complete"

 

@Ankur Bawiskar 

3 REPLIES 3

Ankur Bawiskar
Tera Patron

@Yakshitha 

share your existing BR config and screenshots

BR is on which table etc

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Table : sc_req_item

 

Screenshot 2026-01-16 140938.png

 

Code :

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

    // Add your code here
    var parentReq = current.request;

    var interactionRecord = new GlideRecord('interaction_related_record');
    interactionRecord.addQuery('task', parentReq);
    interactionRecord.addQuery('document_table', 'sc_request');
    interactionRecord.query();
    while (interactionRecord.next()) {

        var interactionGR = new GlideRecord('interaction');
        if (interactionGR.get(interactionRecord.interaction)) {
            if (interactionGR.state != 'closed_complete' || interactionGR.state != 'closed_abandoned') {
                var ritmState = current.state;
                if (ritmState == '3') {
                    interactionGR.state = 'closed_complete';
                } else if (ritmState == '4' || ritmState == '7') {
                    interactionGR.state == 'closed_abandoned';
                }
                interactionGR.update();
            }
        }
    }
})(current, previous);
 

@Yakshitha 

your BR is on RITM and if RITM gets updated and State Changes to Either of those 3 states, it will trigger and update Interaction

You need to debug why RITM is getting it's state updated from Close Complete to Close Incomplete based on SC Task

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader