How to email Project Manager when a project task is updated

mitzaka
Mega Guru

Hi SNC,

I have a case with Project Management - I want to set up a notification which will be sent to the Project Manager of a project, when a project task from that project is updated.

The issue is - when I try to setup a notification for the pm_project_task table, I cannot refer to the Project Manager field, as this field is from the pm_project table.

Another thing I want to do is - is there a way to add a field to the project task form, which shows the project they belong to. I think this would be very useful.

1 ACCEPTED SOLUTION

1) Create new event called "project.task.update.to.pm'




2)Create new email notification


  1)When to send : Send when-->Event is fired-->Event name you can select is :project.task.update.to.pm


  2)Who will receive :Send to event creator-->Event parm 1 contains recipient : true


   


   



3)Create before update business rule




var project_manager = getProject(current.sys_id);



gs.eventQueue("project.task.update.to.pm", current, project_manager, '');





function getProject(planned_task_number)


{


   


   


      var return_sys_id = '';


  var mgr_mail_id ='';


      var pl_task_number = planned_task_number;


   


      var gr = new GlideRecord('pm_project_task');


      gr.addQuery('sys_id', pl_task_number);


      gr.query();


      if(gr.next())


              {


           


              pl_task_number = gr.parent;


              mgr_mail_id = gr.parent.project_manager;


           


              if(gr.parent.sys_class_name == 'pm_project')


                      {


                      return_sys_id = pl_task_number;


  return mgr_mail_id;


                     


              }


           


              else


                      {


                   


                      mgr_mail_id = getProject(pl_task_number);


                   


                   


              }


           


      }


    if(JSUtil.notNil(mgr_mail_id))


    {


    return mgr_mail_id;


    }


   


      else


              {


              return mgr_mail_id;


      }


   


}


View solution in original post

13 REPLIES 13

Kalaiarasan Pus
Giga Sage

dot walking on the parent field , you can access the manager


But in the case where you have several layers of parent tasks? Would that work?


Dimitar, there is a field called top_task , study that....whichever level the task is attached it always has the value of the parent project



eg


Project --> task1-->task2 -->task3



suppose abobe is your project hierarchy...task1 is child of project, task 2 is child of task1 and so on....but all the tasks will have the project number in top_task field.


-Anurag

Had written a function long time back to get the top most project . Check if this helps



var parentClass = current;


var continueTraverse = true;


if(JSUtil.notNil(parentClass.parent))


      {


      while(continueTraverse)


              {


              if(parentClass.sys_class_name != 'pm_project')


                      {


                      continueTraverse = false;


              }


              if(JSUtil.notNil(parentClass.parent))


                      {


                      parentClass = parentClass.parent.getRefRecord();


              }


              else


                      {


                      continueTraverse = false;


              }


      }


      gs.addInfoMessage("Top Most Parent Project Is:"+parentClass.number);


}


else


      {


      gs.addInfoMessage("Current Project Is Top Most Project");


}