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

Swapnil Shirsik
Giga Guru

I would try to write after business rule-insert,update. Example- if i need to copy work notes from sc_req_item to sc_task-

function onAfter(current,previous)

{

current.work_notes=current.request_item.work_notes;

}

Hi Swapnil

Thanks for the reply.

 

The Issue I am facing is that I am able to either copy all work notes using getJournalEntry(-1) or Latest using getJournalEntry(1)

 

But as mentioned I need to copy all the worknotes only during the creation of Task and Later once Task is created Latest worknotes should be copied.

How do I write that condition

Hi Tahzeeb,

So I assume you must be having business rule on incident table after insert and update

1) when incident is inserted -> copy all work notes to task

2) when incident is updated -> only copy latest work notes

getJournalEntry(-1) -> this gives all work notes

getJournalEntry(1) -> this gives latest work notes

What issue you are facing?

Regards
Ankur

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

Hi Ankur,

The Issue is how do I specify the condition which that this is Task creation so all the work notes should be copied

And once Task is created only Latest work notes should be copied.

Writing below script only copies Latest worknotes

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();

}