- 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-10-2020 01:26 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2020 03:30 AM
Hi Ankur,
this is not working, its only copying latest worknotes once the Task is created

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2020 03:43 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2020 04:36 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2020 07:13 AM
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