Copy Project task comments/work notes to parent project

matthew_magee1
Giga Guru

Hi all,

I found this article to copy task comments to the requested item: Copy Task Comments into Request Item History

What I have been asked to do is copy any work notes/comments from the project task to the parent project.

I've create a business rule, that does fire, but the information is NOT being transposed to the project. My ultimate goal is to get the work notes and comments from the task into the Activity area of the parent Project

gs.log('comment: ' + current.comments);

gs.log('wn: ' + current.work_notes);

var gr = new GlideRecord('pm_project');

gr.addQuery('sys_id', current.top_task.sys_id);

gr.query();

while (gr.next()) {

gr.setValue('comments',current.comment);**

gr.setValue('work_notes',current.work_notes);**

gr.update();

}

**again, I'd like these to appear in the Activity area of the parent project

Any help is greatly appreciated-

1 ACCEPTED SOLUTION

Here you go. Use this code in after business rule on project task table


When: after insert5 and update


Conditions Additional Comments Changes OR Work notes changes


Script:



var gr = new GlideRecord('pm_project');


                              if(gr.get(current.getValue('top_task'))){


                                                              if(current.comments.changes())


                                                              gr.comments=current.comments.getJournalEntry(1);


                                                              if(current.work_notes.changes())


                                                              gr.work_notes=current.work_notes.getJournalEntry(1);


                                                              gr.update();


                              }


View solution in original post

13 REPLIES 13

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

Matthew, line 4 of your script is the issue.   Your current script is basically searching the pm_project table for a SysID matching the task's SysID which obviously won't find a record.   The way pm_project_task records are linked to the parent pm_project record is via a column called "parent".   So change line 4 to:


gr.addQuery('sys_id', current.parent);



That should get you fixed.


Hey Michael



Yes, that was a fat-finger mistake. Line 4 has been updated, which pulls in the correct sys_id of the parent project.



For some reason, I'm still not getting any data shoved into the parent project


Here you go. Use this code in after business rule on project task table


When: after insert5 and update


Conditions Additional Comments Changes OR Work notes changes


Script:



var gr = new GlideRecord('pm_project');


                              if(gr.get(current.getValue('top_task'))){


                                                              if(current.comments.changes())


                                                              gr.comments=current.comments.getJournalEntry(1);


                                                              if(current.work_notes.changes())


                                                              gr.work_notes=current.work_notes.getJournalEntry(1);


                                                              gr.update();


                              }


Thanks Abhinay-



I did come across the getJournalEntry method at first and the API said it didn't support my version. Then I realized I had FUJI selected as my version after you made your suggestion. So I changed my version to Geneva on the API and no nasty supporting messages.



Works like a champ-



Thanks!