- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2023 11:49 PM
Hi , i have requirement to show the related list with incident : caller and RITM: Requested for and Catalog task: Request item.Requested for , which are all Active .I tried by creating the Relationship for task table , but am getting only Incident records not other filters,
can anyone please let me know how to achieve this .
Thanks in Advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2023 12:38 AM - edited 01-06-2023 12:59 AM
If I understand correctly, you want to show the tasks belonging to the user displayed in the form. If that is so specifying the user as DYNAMIC90d1921e5f510100a9ad2572f2b477fe or gs.getUserID() is wrong, because it would make the list always display the current user's tasks, no matter which user is in the form. What should be used is:
parent.getUniqueValue()
which returns the sys_id of the user in the form (vs. the user looking @ the form).
E.g:
(function refineQuery (current, parent, currentUserUniqueValue) {
var encodedQueryTemplate = ['active=true',
'ref_incident.caller_id={0}',
'ORref_sc_req_item.requested_for={0}',
'ORref_sc_req_item.request.requested_for={0}',
'ORref_sc_task.request_item.requested_for={0}',
'ORref_sc_task.request.requested_for={0}',
].join('^'),
encodedQuery = encodedQueryTemplate.replace(numberInCurlyBracesPattern(), interpolateFrom([currentUserUniqueValue]));
gs.debug('encodedQueryTemplate: ' + encodedQueryTemplate);
gs.debug(' encodedQuery: ' + encodedQuery);
current.addEncodedQuery(encodedQuery);
function interpolateFrom (replacers) {
return function (fullMatch, replacerIndex) {
return isNaN(replacerIndex) ?
fullMatch :
typeof replacers[+replacerIndex] == 'undefined' ? fullMatch : replacers[+replacerIndex];
};
}
function numberInCurlyBracesPattern () {
return /\{\s*(\d+)\s*\}/g;
}
})(current, parent, parent.getUniqueValue());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2023 11:28 PM - edited 01-05-2023 11:30 PM
Try this, add additional query if required
(function refineQuery(current, parent) {
// Add your code here, such as current.addQuery(field, value);
current.addEncodedQuery('ref_incident.caller_id=' + gs.getUserID() + '^ORref_sc_req_item.requested_for=' + gs.getUserID() + '^ORref_sc_task.request.requested_for=' + gs.getUserID());
})(current, parent);
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2023 12:38 AM - edited 01-06-2023 12:59 AM
If I understand correctly, you want to show the tasks belonging to the user displayed in the form. If that is so specifying the user as DYNAMIC90d1921e5f510100a9ad2572f2b477fe or gs.getUserID() is wrong, because it would make the list always display the current user's tasks, no matter which user is in the form. What should be used is:
parent.getUniqueValue()
which returns the sys_id of the user in the form (vs. the user looking @ the form).
E.g:
(function refineQuery (current, parent, currentUserUniqueValue) {
var encodedQueryTemplate = ['active=true',
'ref_incident.caller_id={0}',
'ORref_sc_req_item.requested_for={0}',
'ORref_sc_req_item.request.requested_for={0}',
'ORref_sc_task.request_item.requested_for={0}',
'ORref_sc_task.request.requested_for={0}',
].join('^'),
encodedQuery = encodedQueryTemplate.replace(numberInCurlyBracesPattern(), interpolateFrom([currentUserUniqueValue]));
gs.debug('encodedQueryTemplate: ' + encodedQueryTemplate);
gs.debug(' encodedQuery: ' + encodedQuery);
current.addEncodedQuery(encodedQuery);
function interpolateFrom (replacers) {
return function (fullMatch, replacerIndex) {
return isNaN(replacerIndex) ?
fullMatch :
typeof replacers[+replacerIndex] == 'undefined' ? fullMatch : replacers[+replacerIndex];
};
}
function numberInCurlyBracesPattern () {
return /\{\s*(\d+)\s*\}/g;
}
})(current, parent, parent.getUniqueValue());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2023 01:04 AM
The result is that for each user that user's active tickets as an affected user are displayed: