Related List - how do I show all Project Tasks with Top_Task of the Project, on the Project?

Shane J
Tera Guru

What query would I use for a Related List that applies to Project, that will show me all Change Requests where the top_task of the parent of the Change Request is the same as the parent.sys_id of the Project?

Basically I want every Change Request that has a Parent that is either the Project, or is one of the Project's children tasks. The thing that ties them all together is 'top_task'.   The problem is, the parent of Change Request is referencing 'Task', which does not have top_task - so is this even possible?


1 ACCEPTED SOLUTION

Yes, that should be right.   Applies to should be Project and Queries from should be Change Request.   If I were to take an educated guess on this one, Id say the problem is on line 7.   Try this:



var gr = new GlideRecord('planned_task'),


      tasks = [parent.sys_id];


gr.addQuery('top_task', parent.sys_id + '');


gr.query();



while (gr.next()) {


      tasks.push(gr.sys_id + '');


}



current.addQuery('parent', 'IN', tasks.join(','));



The plus quote forces the sys_id to a string.


View solution in original post

4 REPLIES 4

tltoulson
Kilo Sage

You should be able to use a Defined Related List where you pull a list of all project tasks where top_task is current.sys_id then apply that list to the change_request.parent.   Example:



var gr = new GlideRecord('planned_task'),


      tasks = [parent.sys_id];


gr.addQuery('top_task', parent.sys_id + '');


gr.query();



while (gr.next()) {


      tasks.push(gr.sys_id);


}



current.addQuery('parent', 'IN', tasks.join(','));



You can of course change the planned_task to project_task if appropriate.   But that is the gist, get all the project tasks and inject their sys_id's into the Defined Related List's query.   I hope this helps.



Kind regards,



Travis


I changed planned_task to pm_project_task but it's not pulling the children tasks in, only where the Project is the Change Request parent.



I just needed to enter this under 'Query with:' under Relationships right?


Yes, that should be right.   Applies to should be Project and Queries from should be Change Request.   If I were to take an educated guess on this one, Id say the problem is on line 7.   Try this:



var gr = new GlideRecord('planned_task'),


      tasks = [parent.sys_id];


gr.addQuery('top_task', parent.sys_id + '');


gr.query();



while (gr.next()) {


      tasks.push(gr.sys_id + '');


}



current.addQuery('parent', 'IN', tasks.join(','));



The plus quote forces the sys_id to a string.


  It's working, thanks Travis!