- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 01:47 PM
Hello, I have been struggling to develop a script that will give me the total RITM count where the user has been the "who is this request for" for a replacement card. Then, I need to store that count into a variable (Replacement Card Count) that is not visible on the submission form. I also don't want to include RITMS whose state is Closed Skipped or Closed Incomplete. I added the script to a Run Script activity within the workflow since the RITM count will not be visible on the form. Here is what I have so far, but I have yet to be successful...
replacementCardCount();
var currentUser = current.variables.who_is_this_request_for;
var catalogItemSysID = gs.getProperty("x_g_nel2_pivi.request.replacement.pivi.request");
var ritmCount = 0;
function replacementCardCount() {
var ritmGR = new GlideRecord('sc_req_item');
ritmGR.addQuery('sc_cat_item', catalogItemSysID);
ritmGR.addQuery('who_is_this_request_for', currentUser);
ritmGR.addQuery('state', 'NOT IN', '7,8');
ritmGR.query();
while (ritmGR.next()) {
ritmCount++;
ritmGR.setValue('replacement_card_count', ritmCount);
}
ritmGR.update();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2024 09:40 AM
This is the code that I ended up using for the requirement. I hope this can help anyone who had a similar issue: var catalogItemSysID = gs.getProperty("x_g_nel2_pivi.request.replacement.pivi.request");
var ritmGR = new GlideRecord('sc_req_item');
ritmGR.addQuery('cat_item', catalogItemSysID);
ritmGR.addQuery('request.requested_for', current.variables.who_is_this_request_for);
ritmGR.query();
if (ritmGR.next()) {
current.variables.replacement_card_count = ritmGR.getRowCount();
ritmGR.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 01:52 PM
@MayrelCerero I would suggest you to add logs in script to validate how many count its giving you.
Also addQuery for item column is wrong, change it to cat_item
ritmGR.addQuery('cat_item', catalogItemSysID);
Thanks,
Harsh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 03:28 PM - edited 03-18-2024 03:28 PM
Hey @MayrelCerero,
Shouldn't you be updating the 'replacement_card_count' of the current record?
If so, try the following script:
replacementCardCount();
function replacementCardCount() {
var currentUser = current.variables.who_is_this_request_for;
var catalogItemSysID = gs.getProperty("x_g_nel2_pivi.request.replacement.pivi.request");
var ritmGR = new GlideAggregate('sc_req_item');
ritmGR.addAggregate('COUNT');
ritmGR.addQuery('cat_item', catalogItemSysID);
ritmGR.addQuery('variables.who_is_this_request_for', currentUser);
ritmGR.addQuery('state', 'NOT IN', '7,8');
ritmGR.query();
if (ritmGR.next()) {
current.variables.replacement_card_count = ritmGR.getAggregate('COUNT');
}
}
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2024 09:40 AM
This is the code that I ended up using for the requirement. I hope this can help anyone who had a similar issue: var catalogItemSysID = gs.getProperty("x_g_nel2_pivi.request.replacement.pivi.request");
var ritmGR = new GlideRecord('sc_req_item');
ritmGR.addQuery('cat_item', catalogItemSysID);
ritmGR.addQuery('request.requested_for', current.variables.who_is_this_request_for);
ritmGR.query();
if (ritmGR.next()) {
current.variables.replacement_card_count = ritmGR.getRowCount();
ritmGR.update();
}