Relationship script partially functioning

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago - last edited 7 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
7 hours ago
I'll start with the obvious - verify the sys_id of the New Contingent Worker catalog item is correct.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
Hi Brad, thanks for the reply. The catalog item sys_id and variable sys_id's are correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
6 hours ago - last edited 6 hours ago
Yeah, had to ask. I would add some log (gs.info) lines to find out what the script is doing, how far it's getting, what it thinks the value of parent.request_item.cat_item, parent.request_item.variables.employee_number... are in this case. This shouldn't be possible any more, but also make sure the variable name on this catalog item doesn't have a stray space at the beginning or end.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
6 hours ago
Hi @DylanBlumenberg ,
Most likely the issue is that the variable sys_id you’re using for the Contingent Worker item isn’t the right one, or that variable isn’t storing the value the way you expect. I’d start by running that debug query on sc_item_option_mtom and confirming the actual variable sys_id + value. Once you swap in the correct one, the related list should start populating the same way as the other two.