Parsing Script Include Output from Client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2022 10:03 AM
We've seen the articles online and in the developer site about calling a script include from your client script in order to do back end processing. I feel like I followed it to the 'T', but this time it isn't working. Some of you chimed in on my reference qualifier question yesterday (thank you!) and my rust is showing.
When I call this Script Include:
from this client script:
I always get null back with the info message on line 14 of the client script, and fail out to the else portion of the _handleResponse function. Worse yet, when I have the script debugger open w/ breakpoints on the Script Include, I don't hit any of them making me think I'm not calling the Script Include correctly (lines 30-33).
Any time the Assignment group (that's our onChange field in the Client Script) is set to anything other than a specific group, it should fire off the Script Include. What did I miss?
- Labels:
-
Script Debugger
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2022 10:10 AM
Couple of things
1) On your client script, change line
isZo.addParam('userID', user); <TO> isZo.addParam('sysparm_user', user);
2) On your script include, remove the parameter userID from the function companyCheck. So it should only say
companyCheck: function(){
3) ON your script include add this as your first line in the function companyCheck
var user = this.getParameter('sysparm_user');

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2022 10:20 AM
Hi there,
Please update your scripts as below:
Script include:
var ZoUtils = Class.create();
ZoUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
companyCheck: function(uID) {
var userID = global.JSUtil.nil(sysparm_userID) ? '' + this.getParameter('sysparm_userID') : '' + uID;
var ZoCheck = new GlideRecord('sys_user');
ZoCheck.addQuery('user_name', userID);
ZoCheck.addQuery('company', 'b42f8eb2db65011068025fc74b9619dd'); //best practice would be to store this sys_id in a sys_property and call it with gs.getProperty() instead
ZoCheck.setLimit(1);
ZoCheck.query();
if (ZoCheck.next()) {
return "True";
} else {
return "False";
}
},
type: 'ZoUtils'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var user = g_user.userName;
if (newValue != 'f8e704e987ca1510dc21ca29cebb353b') {
var isZO = new GlideAjax('global.ZoUtils');
isZO.addParam('sysparm_name', 'companyCheck');
isZO.addParam('sysparm_userID', user);
isZO.getXMLAnswer(_handleResponse);
} else {
g_form.addInfoMessage('Please assign a team member to the case.');
}
function _handleResponse (response) {
if (response == "False") {
g_form.addInfoMessage('Please assign a team member to the case.');
}
if (response == "True") {
g_form.setReadOnly('assigned_to');
g_form.addInfoMessage("bla bla");
}
}
}
If this answer is helpful please mark correct and helpful!
Regards,
Christopher Perry
Regards,
Chris Perry