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

Voona Rohila
Kilo Patron
Kilo Patron

HI @Neelavathi M 

Can you share the relationship you tried.


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

Neelavathi M
Tera Contributor

NeelavathiM_0-1672906355928.png

I am not sure if this is the exact script but i tried it. If changes has to be done please suggest it.

Voona Rohila
Kilo Patron
Kilo Patron

Hi @Neelavathi M 

I gave this a try and it's working as expected.

(function refineQuery(current, parent) {

	// Add your code here, such as current.addQuery(field, value);
current.addEncodedQuery('ref_incident.caller_idDYNAMIC90d1921e5f510100a9ad2572f2b477fe^ORref_sc_req_item.requested_forDYNAMIC90d1921e5f510100a9ad2572f2b477fe^ORref_sc_task.request.requested_forDYNAMIC90d1921e5f510100a9ad2572f2b477fe');

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

Neelavathi M
Tera Contributor

Hi @Voona Rohila 

 

Thanks for your help, Filter is applying statically , means for All user records it is showing same count.

NeelavathiM_0-1672933486872.png

 

 

NeelavathiM_1-1672933544845.png

 

Screenshots from 2 user records, Active is 5 in both, but in 1st image 9 Active incidents , but it is showing as only 5 in Active Tab.