Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How to use getJournalEntry(-1) to produce an array of strings?

CharlesR1
Kilo Guru

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()

}

1 ACCEPTED SOLUTION

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


View solution in original post

14 REPLIES 14

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.


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


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.


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


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.