- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 10:02 PM
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2020 09:35 PM
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:
2. BR on HR Task Table
Expected Results:
HR Task:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2020 09:25 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2020 01:13 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2020 06:01 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2020 07:14 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2020 11:10 AM
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