Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to populate KB HTML Field via script

Priyanka132
Giga Contributor

Hi All,

 

I have been trying to create kb article from problem. I see the values on the field - Article Body (html field on kb) is taken as a plain text eventhough the incoming values from problem are line separated.

 

Any suggestion how can this be fixed

 

1. Problem

find_real_file.png

 

 

 

2. Knowledge created without lines

find_real_file.png

 

 

 

3. Business Rule

var gr= new GlideRecord('kb_knowledge');
gr.initialize();
gr.short_description='From Problem';
gr.text=current.description;
var obj =gr.insert();

gs.addInfoMessage(gr.getDisplayValue()+' : has been created');

 

 

Thanks in advance

1 ACCEPTED SOLUTION

SanjivMeher
Mega Patron
Mega Patron

You can try

 

var gr= new GlideRecord('kb_knowledge');
gr.initialize();
gr.short_description='From Problem';
gr.text=current.description.replace(/\n/g,'<br>');
var obj =gr.insert();

gs.addInfoMessage(gr.getDisplayValue()+' : has been created');


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

3 REPLIES 3

Deepak Ingale1
Mega Sage

Normally KB field gets populated from work notes which supports HTML , any specific reason you are using description?

Thats true, I was using the description field just for testing purpose

SanjivMeher
Mega Patron
Mega Patron

You can try

 

var gr= new GlideRecord('kb_knowledge');
gr.initialize();
gr.short_description='From Problem';
gr.text=current.description.replace(/\n/g,'<br>');
var obj =gr.insert();

gs.addInfoMessage(gr.getDisplayValue()+' : has been created');


Please mark this response as correct or helpful if it assisted you with your question.