Find all records without active children records?

Shane J
Tera Guru

My question is more specific to Request Item and children Catalog Tasks, but the logic would probably apply to any parent/child or one/many relationship.

I'd like to setup a scheduled job to auto-close any RITMs that don't have any active children Catalog Tasks, but I'm not sure how to query to find the records.   We don't assign RITMs to groups in our environment, so if somehow all of the active Catalog Tasks get closed without the parent RITM getting closed, the RITM just hangs out there in an active state.

I suppose another wrench could be that a RITM could be awaiting an Approval, but have no active Catalog Task.  

1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee
ServiceNow Employee

You can do the following to check if your GlideRecord object holds any records.



var inc = new GlideRecord('incident');


inc.addActiveQuery();


inc.query();


inc.HasNext(); //returns true or false depending on whether the inc object has any records.


View solution in original post

10 REPLIES 10

MGanon
Tera Guru

I had a similar question for groups. Here is how I resolved it:

https://community.servicenow.com/community?id=community_question&sys_id=86b8c361db5cdbc01dcaf3231f9619f3