- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2016 03:40 AM
Hello,
The business rule below runs when we close an Incident task. It creates a KB article and everything is populated correctly with the exception of the history , which shows everything in a huge text block, rather than showing as an array of strings. I used ' var na = cmt.split("\n\n");' but this is not working.
Any ideas?
Thanks in advance,
Charles
function onAfter(current, previous) {
var candidate = new GlideRecord("kb_knowledge");
var pNumber = current.number;
var pTitle = current.u_task_title;
var cmt = current.work_notes.getJournalEntry(-1);
var na = cmt.split("\n\n");
candidate.short_description = (pNumber + ' ' + pTitle);
candidate.topic = 'Incident Tasks Reports';
candidate.workflow_state = 'published';
candidate.text = "<h3>Description:</h3>" + current.description + "<br/><h3>Task Status is:</h3>" + current.u_task_status + "<br/><h3>History:</h3>" + (na);
candidate.cmdb_ci = current.cmdb_ci;
candidate.sys_domain = current.sys_domain;
candidate.insert();
gs.addInfoMessage('Knowledge article ' + candidate.number + ' has been published in the Knowledge Base');
current.update()
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-03-2016 06:02 AM
Brad, Goran,
Thank you both for your help. I have not managed to get this to work by replacing the values - instead I changed the script as follows, and this now works fine:
From:
var cmt = current.work_notes.getJournalEntry(-1);
var na = cmt.split("\n\n");
To:
var cmt = current.work_notes.getHTMLValue();
Thanks again,
Charles

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2016 06:07 AM
Splitting on the multiple returns typically works, but you only need to do that if you're iterating through each entry and doing something. What do you mean by it doesn't work? What exactly is happening?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2016 07:06 AM
Hello Brad - thanks very much for your help.
So If we have two comments in the journal, when this gets created in the 'text' field on the KB article, it comes through as:
Description:
Test - This is the description.
Task Status is:
Closed Complete
History:
25-01-2016 15:03:29 - Charles Russell (Work notes) Comment 2,25-01-2016 15:03:23 - Charles Russell (Work notes) Comment 1,
...and what we want is:
Description:
Test - This is the description.
Task Status is:
Closed Complete
History:
25-01-2016 15:03:29 - Charles Russell (Work notes) Comment 2,
25-01-2016 15:03:23 - Charles Russell (Work notes) Comment 1,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2016 10:14 AM
Hi Charles,
You shouldn't have to push it to an array at all to achieve that. getJournalEntry(-1) should print all the entries with a line break in between.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-26-2016 04:23 AM
Hi Brad,
Unfortunately that isn't happening - if I just call 'getJournalEntry(-1)', then I get the whole history in one block of text:
History:
26-01-2016 12:19:35 - Charles Russell (Work notes) This is a yet another test 26-01-2016 12:19:24 - Charles Russell (Work notes) This is another test 26-01-2016 12:19:19 - Charles Russell (Work notes) This is a test