- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2025 10:21 PM
Hey Folks,
I need help with creating union of condition, I have a relationships(Related List) on incident table which have criteria something like below:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2025 03:58 AM
Hey @Ankur Bawiskar , I could not get that to work however I tried realigning of query and that helped reduce the timing, so new criteria looks something like below, this brought down timing to 1/3rd:
current.addEncodedQuery( 'sys_id!=' + parent.sys_id + '^sys_created_onONLast 60 days@javascript:gs.beginningOfLast60Days()@javascript:gs.endOfLast60Days()' + ('caller_id=' + parent.caller_id + '^ORu_behalf_of=' + parent.caller_id + '^ORcaller_id=' + parent.u_behalf_of + '^ORu_behalf_of=' + parent.u_behalf_of ));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2025 10:27 PM
did they not provide the recommendation when you created the case with them?
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-09-2025 10:31 PM - edited 06-09-2025 10:31 PM
@Ankur Bawiskar No we tried but was not able to resolve it, Engineer involved is expert in backend(server side and DB stuff), recommendation provided by them is to have it as UNION as instead of OR.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2025 10:33 PM - edited 06-09-2025 10:44 PM
can you try this? I haven't tested it though.
var incidentIds = {}; // Use object for uniqueness
function addIncidents(query) {
var gr = new GlideRecord('incident');
gr.addEncodedQuery(query);
gr.query();
while (gr.next()) {
incidentIds[gr.getValue('sys_id')] = true;
}
}
var dateFilter = '^sys_created_onONLast 60 days@javascript:gs.beginningOfLast60Days()@javascript:gs.endOfLast60Days()';
var excludeSelf = '^sys_id!=' + parent.sys_id;
addIncidents('caller_id=' + parent.caller_id + excludeSelf + dateFilter);
addIncidents('u_behalf_of=' + parent.caller_id + excludeSelf + dateFilter);
addIncidents('caller_id=' + parent.u_behalf_of + excludeSelf + dateFilter);
addIncidents('u_behalf_of=' + parent.u_behalf_of + excludeSelf + dateFilter);
var sysIdList = Object.keys(incidentIds); // Array of unique sys_ids
if (sysIdList.length > 0) {
current.addQuery('sys_id', 'IN', sysIdList.join(','));
} else {
// Optionally, add a query that matches nothing if no sys_ids found
current.addQuery('sys_id', ''); // This will return no records
}
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-09-2025 10:37 PM - edited 06-09-2025 10:46 PM
Thanks @Ankur Bawiskar let me try and test