Help with relationship between tasks and Projects and Project Tasks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2016 09:48 AM
I created two new fields on my task table: Related Project and Related Project Task
Our managers can add a related project to an SRQ, PRB, etc
Same for a related task (which doesn't have to be under the same project)
I created a new relationship called 'Tickets related to this project'
I'd like to do the following:
- show tasks where project == parent
- show tasks where the project task parent == parent
Here is my relationship so far. Pulling in #1 above is easy, it's the 2nd one that is causing me angst:
Any help is greatly appreciated
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2016 07:25 AM
Figured this out w/ a lot of trial and tribulation
Applies to table: Project
Queries from table: Task
Query with:
//query task table and get records where the related project (u_related_project) == opened project
var query = current.addQuery('u_related_project',parent.sys_id);
var ids = [];
//query pm_project_task table and get records where the project task parent = opened project
var pmtask = new GlideRecord('pm_project_task');
pmtask.addQuery('parent', parent.sys_id);
pmtask.query();
while (pmtask.next()) {
//spit out unique sysids of records in pm_project_task table
//gs.log('unique value: ' + pmtask.getUniqueValue());
//take sys id of project task and use it against the task table
var getTask = new GlideRecord('task');
//find any records where the sysid from the pm_project_task table matches the sysid of the task in the record u_related_project_task
getTask.addQuery('u_related_project_task',pmtask.getUniqueValue());
getTask.query();
ids = [];
while (getTask.next())
//if a record returns, push the task sysid to the ids array
ids.push(getTask.sys_id.toString());
//gs.log('ids: ' + ids);
query.addOrCondition('sys_id', ids);
}