No. of Ritms generated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2024 06:01 AM
hello developers,
I need to calculate how many ritms have been generated by a particular requester/user in a catalog item. Any help is appreciated.
Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2024 06:12 AM - edited 02-23-2024 06:12 AM
Is the requester/user you want to look at in a variable or a field on the sc_req_item table? If it's a variable, you can run a simple script to get the number (which I can help you with if that is the case), if it's a field you can just use the filter on the sc_req_item table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2024 06:12 AM
You can write before insert business rule on sc_req_item table , please check the below script:
(function executeRule(current, previous /*null when async*/) {
// Define the catalog item ID and requester/user ID
var catalogItemId = current.cat_item.toString();
var userId = current.requested_for.toString();
// Create a GlideRecord query to count RITMs
var ritmGr = new GlideRecord('sc_req_item');
ritmGr.addQuery('cat_item', catalogItemId);
ritmGr.addQuery('requested_for', userId);
ritmGr.addQuery('active', true); // Optionally, filter for active RITMs
ritmGr.query();
// Count the number of RITMs
var ritmCount = ritmGr.getRowCount();
gs.info(ritmCount); // you can set it to some field as per requirement
})(current, previous);
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2024 06:26 AM
Hi @servicenow14710,
Try ru this script in Background script
var itemSysID = 'catalog item sys_id';
var userSysID = 'requester/user sys_id';
var agg = new GlideAggregate('sc_req_item');
agg.addQuery('cat_item', itemSysID);
agg.addQuery('requested_for', userSysID);
agg.addAggregate('COUNT');
agg.query();
var count = 0;
if (agg.next()) {
recordCount = parseInt(agg.getAggregate('COUNT'), 10);
}
gs.info('Number of records generated by the requester/user: ' + count);
Please mark my answer as helpful if it worked for you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2024 06:28 AM
Hi @servicenow14710, Do you want to show the count of requests submitted by users for an particular catalog item? If yes, you can try creating a report of type Multi-level Pivot Table on sc_req_item table and configure Quantity in Column and Requested for in Row and have the condition as Item is 'Your catalog item'.
Or
If you want to show the count of catalog items submitted by that particular user on the catalog item then you can try with GlideAjax and Onchange catalog client script on catalog item.
Regards,
Sunil