How do I create a related list on Project Tasks that shows related Planned Task Relationships?

JR42
Giga Guru

Hi.  I am attempting to have the Predecessor and Successor of a task be displayed in a related list.

I created a Relationship under System Definition > Relationships so that I could add a Related List to our Project Task form.  The related list is there and has the information I want, but it is not filtered to only show relationships associated with that Project Task.

 

Relationship details:

Applies to table : pm_project_task

Queries from table: planned_task_rel_planned_task

Query with:

 

(function refineQuery(current, parent) {

	//current.addQuery('number', parent.parent);
	current.addQuery('number', parent.child);

})(current, parent);

 

 

After creating the Relationship, I was able to Configure Related Lists, and it let me add it.

However, the related list shows every single Planned Task Relationship in the system, not just the ones related to that Project Task I have open.  Here is a screenshot showing the related list, and that there are 1214 results;

2024-02-26 14_45_38-task3 _ Project Task _ ServiceNow [DEV] Denovo - DEV INSTANCE.png

 

I can manually filter the list down to what I want, but I would like the Related List to be filtered automatically, based on the Project Task you are viewing the Related List from.

2024-02-26 14_47_39-task3 _ Project Task _ ServiceNow [DEV] Denovo - DEV INSTANCE.png

 

Can anyone help with this?

Should I be using task_rel_task instead of planned_task_rel_planned_task in my relationship?

I've tried a few different script in the Relationship, but nothing had any affect.

 

1 ACCEPTED SOLUTION

Gustav Aldenbra
Kilo Sage

Hi @JR42

 

It wont work to query on the number. you need to query the the parent or child using sys_id. If you want to list all predecessors and successors of a task you should be able to do something like the query below. 

 

(function refineQuery(current, parent) {

	current.addQuery('child', parent.sys_id)
	.addOrCondition('parent', parent.sys_id);
})(current, parent);

 

View solution in original post

2 REPLIES 2

Gustav Aldenbra
Kilo Sage

Hi @JR42

 

It wont work to query on the number. you need to query the the parent or child using sys_id. If you want to list all predecessors and successors of a task you should be able to do something like the query below. 

 

(function refineQuery(current, parent) {

	current.addQuery('child', parent.sys_id)
	.addOrCondition('parent', parent.sys_id);
})(current, parent);

 

Gustav, thank you!  It's working great.