- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2025 01:03 PM
Not sure what the issue is. I am able to call the script include from the window Scripts - Background and works as expected so I am assuming the issue is with how I am calling from client script. I do have the script include Client Callable box checked.
Client Script
var CheckUserLicense = new CheckUserLicense();
var result = CheckUserLicense.getUserLicense('6cccca19f4ead980776706f2f4caa3c6');
gs.print(result);
Depending on the user it will return string of license or noLicense but when calling from client script on the change of the variable I get "There is a JavaScript error in your browser"
Any Help would be greatly appreciated!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2025 08:04 PM - edited 04-10-2025 08:05 PM
Things I would like to inform
1) Client callable script include should not have initialize() method
2) I believe you are trying to re-use the same function from client and server so update as this
Script Include: It should be client callable
var CheckUserLicense = Class.create();
CheckUserLicense.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserLicense: function(uId) {
var userId = this.getParameter('sysparm_userId') || uId;
var result = '';
var grUser = new GlideRecord("sys_user_has_role");
grUser.addEncodedQuery('user.sys_id=' + userId + '^role.nameLIKEitil');
grUser.query();
if (grUser.next()) {
result = "license";
} else {
result = "noLicense";
}
return result;
},
type: 'CheckUserLicense'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var varvarUser = g_form.getValue('add_user_to_group');
var varaddedUser = varUser.split(',').pop();
var ga = new GlideAjax('CheckUserLicense');
ga.addParam('sysparm_name', 'getUserLicense');
ga.addParam('sysparm_userId', varaddedUser);
ga.getXML(licenseResult);
function licenseResult(response) {
var userLic = response.responseXML.documentElement.getAttribute('answer');
alert(userLic);
}
}
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
04-10-2025 01:16 PM
"callTask" should be "ga"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2025 01:26 PM
In addition to "ga" instead of "callTask" in the Client Script, the Script Include should not have the initialize function, which may not matter, but you do need the commented out getParameter line in place of the function argument. Here's an excellent guide to review what is needed, and covers how to return more than one value.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2025 06:23 PM
@mamason Update your scripts as follows.
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
varUser = g_form.getValue('add_user_to_group');
varaddedUser = varUser.split(',').pop();
var ga = new GlideAjax('CheckUserLicense');
ga.addParam('sysparm_name', 'getUserLicense');
ga.addParam('userId',varaddedUser);
ga.getXML(licenseResult);
function licenseResult(response) {
var userLic = response.responseXML.documentElement.getAttribute('answer');
alert(userLic);
}
}
Script Include:
var CheckUserLicense = Class.create();
CheckUserLicense.prototype = Object.extendsObject(AbstractAjaxProcessor,{
initialize: function() {
},
getUserLicense: function(userId){
var userId = this.getParameter('userId')?this.getParameter('userId'):userId;
var result = '';
var grUser = new GlideRecord("sys_user_has_role");
grUser.addEncodedQuery('user.sys_id=' + userId + '^role.nameLIKEitil');
grUser.query();
if(grUser.next()){
result = "license";
}
else
{
result = "noLicense";
}
return result;
},
type: 'CheckUserLicense'
});
Hope this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2025 06:14 AM
@mamason Did you try the changes suggested by me in this post?