how to add 1 or more conditions in related list from task table and display it on user table

Neelavathi M
Tera Contributor

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.

1 ACCEPTED SOLUTION

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());

 

View solution in original post

7 REPLIES 7

Hi @Neelavathi M 

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

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());

 

-O-
Kilo Patron
Kilo Patron

The result is that for each user that user's active tickets as an affected user are displayed:

2023-01-06-2.png

 

2023-01-06-3.png