- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-29-2015 08:52 AM
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.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2015 07:39 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-29-2015 09:11 AM
You'd do a gliderecord query and iterate through all of the active items. Within each item loop you'd do a query on the approval and catalog task tables to see if there are any open records and if not close the item.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2015 07:15 AM
How do you run a query to look for 0 records though?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2015 07:36 AM
before you start the query for the children set a tag to true...
inside the loop looking for kids set the tag to false..
when the loop ends <after the } to end the while> test the tag.. if it is true it has no children and you can close it...
be careful how you do this though....
if you have an item pending item approval it will be active with no children... if you have an item that creates a change request.. it will probably have no children...
if you have an item that invokes some kind of script in the background.. for example an install of softare or spin up of a server.. it will be active and have no children.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2015 07:39 AM
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.