Copy work notes from Itask to Incident
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2023 09:14 AM
Hello Team,
I want to copy worknotes from Incident Task to incident. For which I have created a before business rule which is working fine but when I am using the same code in an after business rule then it's not working. Can someone tell me why?
Code:
(function executeRule(current, previous /*null when async*/) {
var inc = new GlideRecord('incident');
inc.addQuery('sys_id', current.incident);
inc.query();
if(inc.next())
{
inc.work_notes = "Worknotes from " + current.number +':'+"\n\n" + current.work_notes;
inc.update();
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2023 09:34 AM - edited 03-06-2023 09:36 AM
Hi,
It would be helpful if you included what "it's not working" means...because it could deter others from helping who may be able to help, but thinking you have another problem going on.
I believe it "IS" working...it's just not providing the work note as you thought it would...but it's still updating the incident with most of what your script is doing...right? Such as at a minimum creating a work note on the incident with text like:
"Worknotes from " ...etc.
I believe the issue is because the "work_notes" field doesn't retain what was last entered. It's a journal field and thus they are sent to the audit log and posted in activity log. Instead, you'd want to get the last work note like so:
var inc = new GlideRecord('incident');
inc.addQuery('sys_id', current.incident);
inc.query();
if(inc.next())
{
inc.work_notes = "Worknotes from " + current.number +':'+"\n\n" + current.work_notes.getJournalEntry(1);
inc.update();
}
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!