Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Business Rule to Close Catalog Tasks when the parent Requested Item is closed automatically via API

simonellis
Tera Contributor

Hi,

 

I have been tasked with creating a  business rule that will close associated catalog tasks when the parent RITM has been closed via an API Integration.

I was wondering if anyone had ideas around the best way forward, whether there is something simply other than a script.

The scenario is that a RITM has been created and has associated catalog tasks. We have integrations that interact and generate these RITM and now will close them. When we close them we need the associated tasks to be close out post RITM closure.

The API making the call will have the prefix svc_ within it's user name.

2 REPLIES 2

lpruit2
Kilo Sage

Greetings @simonellis. You can do a pretty simple Business Rule if you want to take the pro-code approach. If you are more comfortable with ServiceNow's low-code solutions, you could also create a Flow. I found a very similar existing Business Rule called "Close Tasks Due to Cancellations" that you can use as a template to create your new Business Rule. I hope this information is helpful!

 

When: after

Insert: true

Update: true

 

lpruit2_0-1765424536289.png

 

 

lpruit2_1-1765424576197.png

 



Ankur Bawiskar
Tera Patron
Tera Patron

@simonellis 

you can use after update business rule on RITM

Condition: State Changes to Closed Complete/Close Incomplete/Close Skipped AND Item == <Your Item Name>

Script:

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

    // Add your code here
    var gr = new GlideRecord("sc_task");
    gr.addQuery("request_item", current.sys_id);
    gr.query();
    while (gr.next()) {
        gr.state = 3;
        gr.update();
    }

})(current, previous);

💡 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