- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2023 11:53 AM
Hello folks,
i have created a catalog client script and script include to count related items for the value on the picked variable and based on the number, make variable2 visible or not. I have changed the script include to return number two for testing purposes, however its returning null. That makes me to believe that there is an issue with the logic. However,
I dont know where the issue is. Grateful for any help!
Script include
var Utils = Class.create();
Utils .prototype = {
initialize: function() {},
getCount: function() {
var pSysId = this.getParameter('sysparm_SysId');
var progGR = new GlideRecord('table');
progGR .addQuery('port', pSysId );
progGR .addQuery('pro.active', true);
progGR .addQuery('prote', gs.getProperty('property_name'));
progGR .setLimit(2);
progGR .query();
return '2'; //progGR .getRowCount();
},
type: 'Utils '
};
catalog client script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var UtilsAJAX = new GlideAjax('utils');
UtilsAJAX .addParam('sysparm_name', 'getCount');
UtilsAJAX .addParam('sysparm_SysId', g_form.getValue('variable1'));
UtilsAJAX.getXML(function(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
if (answer === '2') {
g_form.setDisplay('prog', true);
} else {
g_form.setDisplay('prog', false);
}
g_form.addInfoMessage(answer);
});
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2023 12:20 PM
Hi @Spike236 ,
That looks you dont create you element ass Client callable, if you dont select that tag you cant call your script include from a script, first you need to tag the client callable and make some changes:
var Utils = Class.create();
Utils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCount: function() {
var pSysId = this.getParameter('sysparm_SysId');
var progGR = new GlideRecord('table');
progGR .addQuery('port', pSysId );
progGR .addQuery('pro.active', true);
progGR .addQuery('prote', gs.getProperty('property_name'));
progGR .setLimit(2);
progGR .query();
return '2'; //progGR .getRowCount();
},
type: 'Utils '
});
Then you call your function, just make sure is called with the exactly same name you created in your script include:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var UtilsAJAX = new GlideAjax('Utils'); //Make sure is writing in the same method you create in your Script Inclide, capital letters are diferents
UtilsAJAX .addParam('sysparm_name', 'getCount');
UtilsAJAX .addParam('sysparm_SysId', g_form.getValue('variable1'));
UtilsAJAX.getXML(function(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
if (answer === '2') {
g_form.setDisplay('prog', true);
} else {
g_form.setDisplay('prog', false);
}
g_form.addInfoMessage(answer);
});
}
Hope that help you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2023 09:01 PM
@Spike236 To use the script include in the GlideAjax, it should be client callable.
The client callable checkbox should be true and the script should have the code as shown in image above. (the code is missing in your code)
And you need to pass the correct name of script include in the GlideAjax. (You have used the script include name as utils but defined the script include as Utils)
ServiceNow Community Rising Star, Class of 2023