Problem calling a Script Include from a catalog client script

prudhvi67
Tera Contributor

Hello ServiceNow people.

I am getting following error while calling script include from catalog client script. I don't have clue. Can anybody help me out.
(running Client Script "test": ReferenceError: RestrictedOptionsUtil is not defined)

System Property:

prudhvi67_0-1714624834702.png

 



script include:

var RestrictedOptionsUtil = Class.create();
RestrictedOptionsUtil.prototype = {
initialize: function() {},

getRestrictedOptions: function() {
return gs.getProperty('restricted_options');
},

type: 'RestrictedOptionsUtil'
};

Catalog Client Scripts : 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '')
return;

var restrictedOptionsUtil = new RestrictedOptionsUtil(); // Instantiate the Script Include
var restrictedOptionsString = restrictedOptionsUtil.getRestrictedOptions(); // Retrieve restricted options from the system property
var restrictedOptions = restrictedOptionsString.split(',');

if (restrictedOptions.includes(newValue)) {
if (confirm("The selected option is restricted. If you want to request this service, please click OK to be redirected to the ServiceNow form.")) {
top.window.location = url;
g_form.clearValue('application'); //  variable name
}
}
}
2 REPLIES 2

Amitoj Wadhera
Kilo Sage

Hi @prudhvi67 ,

 

Make sure in your Script Include "Client Callable" is checked.

To make a GlideAjax call in a client script, you can refer to the script provided below.

 

// Initialize GlideAjax for the specified script include
var ajaxCall = new GlideAjax('restrictedOptionUtil');

// Add the method name to invoke from the script include
ajaxCall.addParam('sysparm_name', 'getRestrictedOption');

// Make the GlideAjax call and pass the callback function
ajaxCall.getXML(processResponse);

// Callback function to process the response from the script include
function processResponse(response) {
    // Extract the 'answer' attribute from the response
    var answer = response.responseXML.documentElement.getAttribute("answer");
    
    // Display the value using an alert dialog
    alert(answer);
}

 

 

If you find my response helpful, please consider marking it as the 'Accepted Solution' and giving it a 'Helpful' rating. Your feedback not only supports the community but also encourages me to continue providing valuable assistance.

 

Regards,

Amitoj

Community Alums
Not applicable

Hi @prudhvi67 ,

You have to make a GlideAjax call in client script you can refer below script 

var ga = new GlideAjax('restrictedOptionUtil');
      ga.addParam('sysparm_name', 'getrestrictedOptionUtil');
      ga.getXML(getValuleHandler);

function getValuleHandler(response) {
      var answer = response.responseXML.documentElement.getAttribute("answer");
      alert(answer) // you get the value of property here
}

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak