Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

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

Harish Murikinati - hm, interesting. Where should that code go?


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;


      }


   


}


Worked perfectly, I was missing some parts of the logic of the function where you get the Project Manager ID. Thanks everyone!


DaSmith9
Tera Expert

I realize that this thread is already marked as answered, but I wanted to provide an alternative solution to add the Project Manager into the CC field on a pm_project_task notifications. It doesn't directly achieve adding the PM to the To: field on your notifications, but in some circumstances, the CC line is appropriate and serves to include the PM on the project task notification.



1) create a mail script called pm_project_task_cc_project_manager or whatever you like.


2) script contents


      email.addAddress("cc", current.top_task.project_manager.email, current.top_task.project_manager.getDisplayValue());


    (addAddress(String type, String address, String displayname): type can be cc or bcc - Scripting for Email Notifications - ServiceNow Wiki)




        mail_script.PNG




3) Add mail script call to your notification in the html editor


      ${mail_script:pm_project_task_cc_project_manager}


        mail_script_call.PNG


This method takes advantage of the top_task reference field on the pm_project_task record where you can dot walk to the project_manager.email value. The iterations for getting to the parent task with the project manager are performed on the dictionary item for top_task, and you do not have to script the iterations to get to the parent.project_manager.email value. It works because the project_manager field is on the parent/top_task which is of the pm_project type.



-Daniel