- 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-26-2016 06:59 AM
Ahhh ok. I had missed that you are pasting it into an html field, sorry about that. I think you should be able to convert the javascript line breaks (\n) to html line breaks (<br/>) and then have them show up correctly in the knowledge article.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2016 01:01 AM
Hi Brad,
Ok so I've changed the line to var na = cmt.split('<br/><br/>'); however the problem has still not been fixed - I'm still seeing all the history entries on one line.
Do you have any further ideas?
Thanks again for all your help,
Charles

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2016 06:21 AM
I don't think you need to split on <br/>. I think your issue is that in javascript a line break is \n, but when you add that to the html, the html doesn't know what to do with it as an html line break is <br/>. I think you need to do a replace and replace the \n line breaks with <br/> so that the html knows what to do with them.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2016 06:39 AM
Thanks Brad - I thought that I had done that already by replacing 'var na = cmt.split("\n\n");' with 'var na = cmt.split('<br/><br/>');' Am I missing something?
Cheers,
Charles

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2016 06:42 AM
No, split looks at your string and splits it into an array using whatever argument passed as the separator. You need to use the replace() method.