How do I filter the related list based on the displayed parent record value?

nikhil88
Tera Contributor

My objective is to define a filter for the related list (in this case , its the "task_ci" table) so that it displays only records that match the configuration item name residing on the parent configuration record form ("cmdb_ci"). I have created a relationship record that has the following values: 

find_real_file.png

I am very new to servicenow and I am positive that it has something to do with the query , I would greatly appreciate any assistance with this issue. 

I want a default filter created similar to the screenshot below , see "Tasks" tab. Thank you 🙂 

 

find_real_file.png

 

 

 

1 ACCEPTED SOLUTION

SanjivMeher
Kilo Patron
Kilo Patron

You relationship record should have query

 

current.addQuery('ci_item',parent.sys_id);


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

9 REPLIES 9

sachin_namjoshi
Kilo Patron
Kilo Patron

Use below relationships

 

 

(function refineQuery(current, parent) {

	// Add your code here, such as current.addQuery(field, value);
	
	current.addQuery('cmdb_ci',parent.sys_id);

})(current, parent);

 

find_real_file.png

 

Regards,

Sachin

SanjivMeher
Kilo Patron
Kilo Patron

You relationship record should have query

 

current.addQuery('ci_item',parent.sys_id);


Please mark this response as correct or helpful if it assisted you with your question.

nikhil88
Tera Contributor

Thank you Sachin for the quick response but I am attempting to create a duplicate of the OOB related list called "Affected by Task" which lists the all the tasks associated with Affected CIs which reside in "task_ci" table. 

 A result wherein the tasks from the table are by default filtered based on the parent record in this case "Testing CR" , see screenshot:

Affected by Task [OOB Related List]

find_real_file.png

 

Custom Related List - Affected CIs (Related tasks)

 In this related list , I created it displays all the tasks in the "task_ci" table and is not filtering by default on the parent record in this case "Testing CR"

find_real_file.png

 

Any suggestions on how I can get a related list that mimics the OOB related list called "Affected by Task". Thank you again for your help , much appreciated!!

nikhil88
Tera Contributor

Thank you Sanjiv , the query worked for me!!