Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Copying worknotes from Incident to Task

Tahzeeb
Giga Expert

Hi All,

 

I need some help on below requirement

I need to copy work-notes from Incident to Task but with the condition that all the work-notes should be copied only at the time of Task creation and later only recent work-notes should be copied.

-Tahzeeb

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi Tahzeeb,

 

Are you trying this logic on HR Case and HR Task table? If yes, please follow the below screenshots on Human Resources : Core Scope.

 

1. BR on HR Case table:

find_real_file.png

 

find_real_file.png

 

2. BR on HR Task Table

 

find_real_file.png

 

find_real_file.png

 

 

Expected Results:

HR Task:

find_real_file.png

View solution in original post

31 REPLIES 31

Hi,

in the after insert/update business rule you can determine the operation whether it is insert or update using current.operation()

if(current.operation() == 'insert'){

// do something

var gr = new GlideRecord('incident'); 

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

gr.query();

while(gr.next())

{

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

}

}

else if(current.operation() == 'update'){

// do something

var gr = new GlideRecord('incident'); 

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

gr.query();

while(gr.next())

{

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

}

}

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

this is not working, its only copying latest worknotes once the Task is created

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

if you want all work notes then

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

 

Thanks,
Ashutosh

Hi Tahzeeb,

So during insert it will be the only entry in work notes for that table so the latest and all both will have same value

Example: if task is created just now and user entered testing in work notes then testing is the only word as of now in work notes; it won't have any previous value

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

Here are the steps to reproduce

1)Create an Incident

2)Add the Work-notes say Test 1,Test 2,Test 3...

(Test 1, Test 2, Test 3 are different work notes added to the Incident at different time before the Task was created)

3)Create a Task from Incident

At this Stage All the work-notes from Incident i.,e., Test 1,Test 2, and Test 3 should be copied

4)At this stage we already have Task Created

5)Now Add the work-note Test 4

6)At this stage only Latest Work note which in this case is Test 4 should be copied to the Task

 

This is what I am trying to achieve