Sow - Business Rule

keerthana10
Tera Contributor

Hi  Experts,  In Sow View , When an interaction is created and then converted to other ticket types such as incident, change, request and problem. When these tickets are complete, the interaction should also be marked as complete. 

 

I Created BR for this requirement but is not working. Please help me on this

 

Thanks

 

 

Script:

 

 if (current.state == 7) { 
        if (current.parent) {
            var parentGR = new GlideRecord('interaction');
 
            if (parentGR.get(current.parent)) {
gs.info("Found parent task: " + parentGR.number + ", State: " + parentGR.state);
 
                
                if (parentGR.state != 3) { 
                    parentGR.state = 3;
                    parentGR.update();
gs.info("Parent task closed: " + parentGR.number);
                } else {
gs.info("Parent task already closed.");
                }
            } else {
gs.info("No parent task found with sys_id: " + current.parent);
            }
        } else {
gs.info("Incident has no parent.");
        }
    }
}
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@keerthana10 

you can use after update business rule on Task table.

Whenever INC/PRB/CHG is created from interaction, an entry is made into this table "interaction_related_record"

 

AnkurBawiskar_0-1749734403606.png

 

You can use this table to know which interaction to close when INC/PRB/CHG is closed

Business rule: task table

Condition: 

AnkurBawiskar_1-1749734538909.png

 

Script:

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

    // Add your code here
    var gr = new GlideRecord("interaction_related_record");
    gr.addQuery("task", current.sys_id);
    gr.query();
    if (gr.next()) {
        var interactionRec = gr.interaction.getRefRecord();
        interactionRec.state = 'closed_complete';
        interactionRec.active = false;
        interactionRec.update();
    }

})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

7 REPLIES 7

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @keerthana10 

 

Something similar:

 

https://www.servicenow.com/community/developer-forum/how-to-close-the-interaction-after-incident-or-...

 

https://www.servicenow.com/docs/bundle/yokohama-it-service-management/page/product/service-operation...

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Hi @Dr Atul G- LNG  i checked those 2 links , the first link totally different for my requirement .

1. if i try closed to any child record like (incident , problem , change and request) , then the parent interaction record should be closed.

Hi @keerthana10 

 

I shared the link as a reference, but in practice, as soon as the child record is created, the interaction must be closed. There is no purpose in keeping two records open for the same issue.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Hi @Dr Atul G- LNG  i Agreed this , but  customer wants this requirement