- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2020 06:21 PM
I am trying to reuse some code I found on another post for building relationships. I am still learning scripting. But I fear trying to query off RITM variables is tossing me for a loop and I could use some help. My goal is to build a related list for my facility table to show all request items that have the facility selected in the RITM's variable field site_location_1 or site_location_2. Ideally I dont want to have to define the catalog item specifically, because I have many catalog items that use this field name. But if I do, would need to build an array of cata item names.
(function refineQuery(current, parent) {
// Add your code here, such as current.addQuery(field, value);
var ritms = [];
var gr = new GlideRecord('sc_req_item');
gr.addQuery('cat_item.variables.site_location_1',parent.sys_id);
gr.addQuery('cat_item.variables.site_location_2',parent.sys_id);
gr.query();
while(gr.next())
{
ritms.push(gr.getValue('sys_id'));
}
current.addEncodedQuery(ritms);
})(current, parent);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2020 04:04 AM
I played around with the code some and got this working. Thank you for the help!
(function refineQuery(current, parent) {
// Add your code here, such as current.addQuery(field, value);
var ritms = [];
var gr = new GlideRecord('sc_req_item');
gr.query();
while (gr.next()) {
var siteLoc1 = gr.variables.site_location_1;
var siteLoc2 = gr.variables.site_location_2;
if (siteLoc1 == parent.getValue('sys_id') || siteLoc2 == parent.getValue('sys_id')) {
ritms.push(gr.getValue('sys_id'));
}
}
current.addQuery('sys_id', ritms);
})(current, parent);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2020 05:26 AM
Thanks for the update, Steve. Would you mind marking my response as helpful/correct if I am able to resolve your query? thanks
- Pradeep Sharma