
- 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
02-03-2025 09:18 AM - edited 02-04-2025 09:00 AM
My script include only returns true of false based on if it is a Self Service KB article or not. How would I get it to return both. Also the script appears to be updating the comments as I can see it display the updated URL but it is almost like the comment is being committed a spit second before the update the comment. See screenshot below with the correct URL in the comments.
Below is my script include:
var CheckKnowledgeBase = Class.create();
CheckKnowledgeBase.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isSelfService: function() { //function to verify if a KA is in the Self-Service Knowledge Base
var number = this.getParameter('sysparm_number');
var gr = new GlideRecord('kb_knowledge');//Glide Record query to search for the KB Article
gr.addQuery('number', number);
gr.query();
if (gr.next()) {
if (gr.kb_knowledge_base.getDisplayValue() == "Self-Service") {//Check if artical is part of the Knowledge base.
return true;
} else {
return false;
}
} else {
return false;
}
},
type: 'CheckKnowledgeBase'
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2025 09:02 AM
@Harsh Vardhan can you share your code that you use in your PDI?

- 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
02-05-2025 08:53 AM
That isn't a real test because you are not using the attach article functionality you are just posting a comment.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2025 09:47 AM
Ok so I brought all my script over into my PDI. It does the same thing. Where you see it change the comments but what is posted is not correct. If I comment everything out in my script and just do the 3 lines of code it works.
var comment = g_form.getValue('comments');
var newComment = comment.replace("kb_view.do?sys_kb_id", "prism?id=kb_article&sys_id");
g_form.setValue("comments", newComment);
Seems to be some sort of timing issues. The question now is how do I get around it.