- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2024 05:25 AM
Hello,
I need to create a business rule that will count how many requests for the same catalog item any user has raised and display that as a message on a RITM form. I've come up with something like this:
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2024 05:39 AM
@LukaszW Have you created this BR on sc_req_item table? If yes then there is no such column as sc_cat_item on it. The column which contains catalog item reference is cat_item. Please update your script as follows and see if it works.
var aggrequest = new GlideAggregate('sc_req_item');
aggrequest.addAggregate('COUNT', 'cat_item');
aggrequest.addQuery("cat_item", "=", current.cat_item);
aggrequest.addQuery("requested_for", "=", current.requested_for);
aggrequest.query();
while (aggrequest.next()) {
var msg = current.requested_for.name + " has raised " + aggrequest.getAggregate('COUNT', 'cat_item') + " identical requests";
gs.addInfoMessage(msg);
}
Hope this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2024 05:39 AM
@LukaszW Have you created this BR on sc_req_item table? If yes then there is no such column as sc_cat_item on it. The column which contains catalog item reference is cat_item. Please update your script as follows and see if it works.
var aggrequest = new GlideAggregate('sc_req_item');
aggrequest.addAggregate('COUNT', 'cat_item');
aggrequest.addQuery("cat_item", "=", current.cat_item);
aggrequest.addQuery("requested_for", "=", current.requested_for);
aggrequest.query();
while (aggrequest.next()) {
var msg = current.requested_for.name + " has raised " + aggrequest.getAggregate('COUNT', 'cat_item') + " identical requests";
gs.addInfoMessage(msg);
}
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2024 06:51 AM
YES! Now it's working, thank you very much. I was pretty sure that I also tried to do this that way but seems like I didn't 🙂 Thank you 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2024 05:44 AM
Hi,
Instead of showing this as a message on the screen with the number, it sound like it could better serve as a related list to show.
Here's how you can do.
Create a new relationship (navigate to System Definition > Relationships)
Fill out a name (i.e. Same requested item by same user)
Applies to table: sc_req_item
Queries from table: sc_req_item
Script:
current.addQuery('requested_for', parent.getValue('requested_for'));
current.addQuery('cat_item', parent.getValue('cat_item'));
Submit the new relationship record.
Configure the related list on sc_req_item, and add the new relationship created (search for the name you gave it).
Done!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2024 05:48 AM
And if you want to filter out the current record from the related list, add this to the scripted query.
current.addQuery('sys_id', '!=', parent.getUniqueValue());