
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2025 02:08 PM
Hey everyone, I'm trying to create a relationship on the sc_task table and I'm running into some issues. The goal is to take the value of the employee_number catalog item variable from the current record and look up any other sc_task records that contain that same value on the employee_number variable. Below is what I have so far but it's returning every sc_task record in the system. Does anyone know where I went wrong?
Things worth noting:
- 'Applies to table' and 'Queries from table' are both sc_task.
- There is a normal variable named employee_number and a variable set variable named employee_number. This script should look for values from both variables.
- In the log, gs.info is returning the correct employee_number variable.
(function refineQuery(current, parent) {
var employeeNumber = parent.request_item.variables.employee_number;
gs.info('Related List Debug. Value found is: ' + employeeNumber);
current.addQuery('request_item.variables.employee_number', employeeNumber);
})(current, parent);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2025 01:52 AM
variables are linked with RITM and not with sc_task
Something like this should work, assuming you want to see related sc_tasks with same variable value
(function refineQuery(current, parent) {
var employeeNumber = parent.request_item.variables.employee_number;
var variableSysId = ''; // give here the sysId of that variable from item_option_new table
var ritmArr = [];
var gr = new GlideRecord("sc_req_item");
gr.addQuery("variables." + variableSysId, employeeNumber);
gr.query();
while (gr.next()) {
ritmArr.push(gr.getUniqueValue());
}
current.addQuery('request_item.sys_id', 'IN', ritmArr.toString());
})(current, parent);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2025 08:54 AM
Glad to help.
Happy learning !
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader