
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2025 12:49 PM - edited 01-30-2025 12:50 PM
I have the below client script to update the URL of the article so that it provides the service portal view of the article since most user cannot see it in the standard UI. It does not work in Service Operations Workspace. Is there some other place I would need to use this code so it works in SOW.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
if (newValue.includes('kb_view.do')) {
g_form.getReference('caller_id', company);
}
}
function company(caller){
if (caller.company == '357bc3411b39d8503d4477761a4bcbaa'){
var comment = g_form.getValue('comments');
// retrieve KB link between [code] blocks
var commentLink = comment.substring(
comment.lastIndexOf('[code]') + 6,
comment.lastIndexOf('[/code]')
);
// retrieve KB number from URL
var kbNumberSub = commentLink.match(' >(.*) : ')[1];
var kbNumber = trim(kbNumberSub);
//call script include to verify if self-service kb
var ga = new GlideAjax('CheckKnowledgeBase');
ga.addParam('sysparm_name', 'isSelfService');
ga.addParam('sysparm_number', kbNumber);
ga.getXML(isSelfServiceParse);
}
else{
alert('This user is not an employee and does not have access to view KAs');
g_form.clearValue('comments');
}
}
function isSelfServiceParse(response) { //Verify responce is true and set comments if correct.
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == "true") {
var comment = g_form.getValue('comments');
g_form.setValue("comments", comment.replace("kb_view.do?sys_kb_id", "prism?id=kb_article&sys_id"));
} else {
var userGA = new GlideAjax('getUserData');
userGA.addParam('sysparm_name', 'checkFulfiller');
userGA.addParam('sysparm_user_sys', g_form.getValue('caller_id'));
userGA.getXML(checkFulfillerParse);
}
}
function checkFulfillerParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == "false") {
g_form.clearValue('comments');
alert("The KA you tried to attach is for fulfillers only. The caller cannot view this article.");
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2025 11:56 AM
@Brian Lancaster I just tried to use onChange client script on comment field, if i mention any url it should replace to different url and that has updated the correct result.
Have you tried to reproduce it on your PDI ? your updated script looks fine to me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2025 11:23 PM
Did you try to debug by adding alerts what's the outcome?
Did you try to use getXMLAnswer() for ajax?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2025 08:44 AM - edited 01-31-2025 08:44 AM
Tossed in some alerts. It appears to get to this code and then stopes working in SOW. Fulfiller Standard UI it works fine. I get the alert that says before retrieve kb number but the alert that should be the KB number I don't get.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2025 09:43 AM
@Brian Lancaster Try to validate match and trim method output.
Also check browser console log , see if any error coming due to the function used inside this client script.
eg:
alert('before retrieve kb number ' + commentLink.match(' >(.*) : ')[1] );
// retrieve KB number from URL
var kbNumberSub = commentLink.match(' >(.*) : ')[1];
alert (' KB Number ' + trim(kbNumberSub) );
var kbNumber = trim(kbNumberSub);
Thanks,
Harsh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2025 10:22 AM
I get the before retrieve KB number. But not the other alert you suggested. These appear in the console log right after the alert before retrieve KB Number.