How do I print dynamic text in a KB article based on URL variables?

jeremyduffy
Kilo Guru

I have a server that will catch links to old broken URLS and redirect it to a knowledgebase article. That's all well and good, but I'd much rather have a quick script update the URL and print it as a clickable link instead.

 

As psuedocode:

 

function onLoad() {
	//psuedocode
	
	// Check if they're viewing the KB I wrote to catch the redirects
	if (<theKBnumber> == KB4090329){
		var origDest = urlVariables[origURL];
		// Take for granted I have a function that spits out a corrected URL here
		var fixedDest = fixUrl(origDest);
		
		writeToKB(`
			The URL you tried to load is no longer valid, but here's a replacement link:
			<a href=fixedDest>fixedDest</a>
			You can click the above, but please also fix your bookmarks if you want to avoid this page in the future.
		`);
	}
}

 

So far, I can't get any kind of message or text to appear when loading KB articles with Client Scripts. I've been trying everything I could find, but nothing seems to work or display:

function onLoad() {
	var heywo = "hello world";
	this._knowledgeHelper.addUniqueInfoMessage("test message",'');
	alert(heywo);
	console.log(heywo)
    //msg = getMessage(heywo);
    //g_form.addErrorMessage(msg);
}

 

Is this not something that's possible in ServiceNow?

1 ACCEPTED SOLUTION

jeremyduffy
Kilo Guru

Based on another question I asked, this isn't possible with client scripts and has to be done through direct edit of the widgets that display KBs.

View solution in original post

1 REPLY 1

jeremyduffy
Kilo Guru

Based on another question I asked, this isn't possible with client scripts and has to be done through direct edit of the widgets that display KBs.