How to use Script in KB Article?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2016 04:49 AM
Hi guys, I already asked a question regarding that why th KB html editor discard some characters from the HTML source. My problem is that whenever I save the HTML field, discarded, and therefore I cannot make a proper mailto url to open a new email with mutliple body. Here is is the original issue.
I have found a solution that I create an OnLoad Client Script, which add characters where I needed, so the mailto url is good. Here is the Client Script:
function onLoad() {
var number = g_form.getValue('number');
//alert(number);
if (number == 'KB0010006'){
var str = g_form.getValue('text');
var res = str.replace(/%5D/g, "%5D").replace(/Dear%20Team%20Support%2C/g, "Dear%20Team%20Support%2C").replace(/Best%20Regard/g, "Best%20Regard");
g_form.setValue('text',res);
}
}
It work really well, I click on the KB article on "mailto" link, and have a new mail with multiple lines in the body (where I have character)
BUT! It is only works in our DEV and TEST instance.
Not in SB and PRD instances! Why? The version is the same in all: glide-helsinki-03-16-2016__patch4-08-10-2016
It seems for me in SB and PRD some script discards the . I cannot figure it out. In kb editor HTML source I get , but when I "View Article" that lost, something discard it when the KB UI page rendered
I'm just wondering how could I add that script above to the kb_view UI Page? Do I need to create a UI Macro or Script Include? Then how to add that to UI Page? Does it worth to try?
Any other suggestion?
Still the main cioncern why ServiceNow does not let me save in HTML field characters?
Many thanks!
Laszlo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2016 05:11 AM
I personally absolutely hate that stupid WYSIWYG editor in ServiceNow (and the one on community is just as bad). It loves to add in extra code and take out other pieces of code. Sometimes just clicking into the HTML field and clicking out will cause it to add extra <p> and <big> tags. Ugh.
Anyways, kb_view is what the page calls when viewing an article. Best bet would probably be to add some Jelly into the UI Page that does that for you.
I'm not entirely sure how, but you should just be able to add the onLoad script (without the onLoad part since it renders onLoad already) between a new <script> block at the top.
Normally I create my KB HTML in another application and then copy/paste the source into the stupid WYSIWYG. Then if I have any links I usually just manually update them with the add link button or whatever in the editor.
It also may be worth checking into if there is some security setting that is intentionally doing that. I would have no idea what, but maybe something to check on next?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2016 05:35 AM
Thanks for your input! Simple put the code between script tags on KB UI page does not help, do anything. This issue gives me so many grey hairs. Finally found a solution with that Client Script but does not work on all instances . So sad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2016 11:20 AM
Ok, my update is that, if I change the "text" field's type on KB from Translated HTML to HTML then the above client script works well.
Do you have any idea why not with Translated HTML type? Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-22-2016 04:44 AM
I have no idea! Probably just another one of those quirky ServiceNow things to make a note of.
