- 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
‎02-03-2016 12:55 AM
Ok thanks Brad - I don't know how to use the replace() method - I've looked for examples on the wiki and community but I can't find anything that helps - would you be able to point me in the right direction?
Thanks,
Charles
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-03-2016 01:41 AM
replace('WHAT_YOU_LOOKING_FOR','PUT_THIS_INSTEAD');
in your case probably something like .replace('<br>','\n');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-03-2016 01:42 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-03-2016 02:14 AM
Thanks Goran - this is a new one for me!
I have changed the code as below, but now the result is undefined:
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");
var rep = na.replace("\n","<br>");
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>" + (rep);
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()
}
Where am I going wrong?
Thanks again
- 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