Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Need Refine Query for related list

sirisha22
Tera Contributor

Hi ,

TASK:I have a parent table(portfolio) with the related list (project),now need to create another related list (action)depend on projects field in existing related list field

Thanks in advance!

 

1 REPLY 1

Mike Allen
Mega Sage

Build a Relationship under System Definition, have it query from the action table and apply to the portfolio table.  In the script, query project where parent = parent.sys_id (which is the portfolio).  Something like this:

(function refineQuery(current, parent) {

// Add your code here, such as current.addQuery(field, value);
var proj_list = '';
var proj = new GlideRecord('pm_project');
proj.addQuery('parent', parent.sys_id);
proj.query();
while(proj.next()){
proj_list += proj_list == '' ? proj.sys_id : ',' + proj.sys_id;
}

current.addQuery('parent', 'IN', proj_list);
})(current, parent);

 

find_real_file.png