Relationship script partially functioning

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
9 hours ago - last edited 9 hours ago
Hi all, I have this relationship script I'm having trouble with. It applies to and queries from the sc_task table. The purpose of it is to show related new hire tickets. It works by looking at the employee_number catalog item variable that they all have and builds a list of tickets with that same employee number. It's set up to only work on three types of tickets; New Hire Request, New Contingent Worker Request, and tickets created from a New Hire Technology order guide.
The issue that I'm experiencing is that the related list doesn't appear on New Contingent Worker Request tickets. It does show up on New Hire Request and New Hire Technology tickets though.
Things I've tried:
- I adjusted the criteria on line 4 to include the New Contingent Worker sys_id (a45f26d71bba611051582023604bcb72).
- On line 16, I added the sys_id (415f2a1b1bba611051582023604bcbca)
of the employee number variable on the New Contingent Worker request. - I cleared the cache and impersonated other users.
- Verified that the related list is configured to show on the sctask form. Removed it and re-added it.
- Verified that both tickets are using the same view.
- Verified manually that the records it should be finding exist.
What am I missing here?
(function refineQuery(current, parent) {
// Only runs on New Hire Request, New Contigent Worker tickets or New Hire Technology order guide tickets
if (parent.request_item.cat_item == '0171a9cadb2cd0101739327e9d9619d7' || parent.request_item.cat_item == 'a45f26d71bba611051582023604bcb72' || parent.request.u_order_guide == '2818c6431b7be9104143ebd5604bcb6e') {
// Grab employee number from the parent RITM's variable
var employeeNumber = parent.request_item.variables.employee_number;
// If the employee number is empty, no need to proceed. Return no records.
if (!employeeNumber) {
current.addQuery('sys_id', '-1');
return;
}
// Sys_ids of the variables to search for (from the item_option_new table)
var variableSysIds = '245957951ba0b1104143ebd5604bcbac,e68171c2dbacd0101739327e9d9619a8,415f2a1b1bba611051582023604bcbca';
var ritmSysIds = [];
// Querying sc_req_item.variables.
var grMtom = new GlideRecord('sc_item_option_mtom');
// Find variable instances that match the specified variable definitions AND the employee number.
grMtom.addQuery('sc_item_option.item_option_new', 'IN', variableSysIds);
grMtom.addQuery('sc_item_option.value', employeeNumber);
grMtom.query();
// Collect the sys_ids of the matching Requested Items (RITMs)
while (grMtom.next()) {
ritmSysIds.push(grMtom.getValue('request_item'));
}
// If no RITMs were found, stop and return no records.
if (ritmSysIds.length === 0) {
current.addQuery('sys_id', '-1');
return;
}
// Filter the current related list to show records whose request_item is in our list.
current.addQuery('request_item.sys_id', 'IN', ritmSysIds);
} else {
// If the parent item is not the one we're looking for, return no records.
current.addQuery('sys_id', '-1');
}
})(current, parent);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
8 hours ago
Hi @aruncr0122, when I manually run the query, I get results that I expect to see on the sc_task.
The last record on the list is the RITM of the ticket I'm trying to see this information on and it's stored as a string value.
When I search for the variable sys_id's via SNUtils, each of them bring me to item_option_new record view. Each are single line text type variables.