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

Kunal Varkhede
Tera Guru

Hi,

 

In addition to above point try below

Before Creation of Task copy the worknote using below script

current.getJournalEntry(1); //for latest comment

current.getJournalEntry(-1) //for all comment 

 

After task is created latest worknote should be copied using below script

var notes="";
var gr=new GlideRecord('sys_journal_field');
gr.addQuery('element', 'work_notes');
gr.addQuery('element_id', current.sys_id);
gr.orderByDesc('sys_created_on');
gr.setLimit(1);
gr.query();
while (gr.next()) {
notes = gr.value.toString();
}

 

Please Mark correct/helpful answer if it help you in any way

Thanks,

Kunal

Hi Kunal

Thanks for the reply,

 

The Issue is how do I differentiate in script that Before and after Task creation scenario

What should be the condition for that

Pooja Mallikarj
Kilo Sage

Hi Tahzeeb,

You need to create two BRs for your requirement.

One is Before Insert BR on incident_task table for updating all work notes  during incident task creation.try with below code

// Add your code here
var gr=new GlideRecord('incident');
gr.addQuery('sys_id', current.incident.sys_id);
gr.query();
while(gr.next())
{
current.work_notes=gr.work_notes.getJournalEntry(-1);
}

And other is After Update BR on incident table and try to add conditions like work notes/additional comments changes and try to execute below script.

var gr=new GlideRecord('incident_task');
gr.addQuery('incident.sys_id',current.sys_id);
gr.query();
while(gr.next())
{
gr.work_notes=current.work_notes.getJournalEntry(1);
gr.update();
}

please mark it as correct/helpful if it really helps for you.

Thanks,

Pooja M

Hi Pooja,

 

I tried this approach but its not working. Below is the requirement

 

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

Hi Tahzeeb,

Yes ,I tried same test cases in my PDI and it worked perfectly.

And you can see below code and screenshots which are similar as my answer and it worked as your requirement.

Thanks,

Pooja M