How do I get my custom Project Task fields to populate with the Predecessor and Successor tasks

JR42
Giga Guru

Hello!  I need to display the Predecessor and Successor (from Dependencies) on each Project Task.

The idea is that the person looking at the Project Task will be able to easily see if that task has predecessors or successors.

 

I've created two new reference fields, 'Successor Task' (u_successor_task), and 'Predecessor Task' (u_predecessor_task). 

Then I created a Business Rule to run After Insert, Update or Delete.  It uses the following script, which I do not think is correctly finding the Predecessor and Successors from the Dependencies, and definitely isn't population my new fields.

(function executeRule(current, previous /*null when 'insert' or 'delete'*/) {
    // Get the successor (current task) sys_id
    var successorSysId = current.child.toString();
    // Get the predecessor (dependent task) sys_id
    var predecessorSysId = current.parent.toString();

    // Update the Successor's 'Predecessor Task' field
    var successor = new GlideRecord('pm_project_task');
    if (successor.get(successorSysId)) {
        successor.setValue('u_predecessor_task', predecessorSysId); 
        successor.update();
    }

    // Update the Predecessor's 'Successor Task' field, if applicable
    var predecessor = new GlideRecord('pm_project_task');
    if (predecessor.get(predecessorSysId)) {
        predecessor.setValue('u_successor_task', successorSysId); 
        predecessor.update();
    }
})();

 

Does anyone have a solution for this?

1 ACCEPTED SOLUTION

JR42
Giga Guru

I decided to go with a related list instead.

View solution in original post

5 REPLIES 5

good to know, always choose the  simple and viable approach. 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution