Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Client script calling script include scope mismatch

chrisn_
Mega Guru

I have created a scoped application that I am allowing most access to. I have a catalog client script which is trying to call a script include and I am getting a Script: x_unoci_rapid_retu.RRCall not found in scope: x_unoci_rapid_retu, and HTTP Processor class not found: x_unoci_rapid_retu.RRCall: no thrown error.

The client script looks like this 

var ga = new GlideAjax('RRCall');

it is in an scoped application but the global checkbox is checked.

The script include:

var RRcourseinfo = Class.create();
RRcourseinfo.prototype = Object.extendsObject(AbstractAjaxProcessor,{
RRCall: function() {

The script include is also in the same scoped application but is accessible from all application scopes.

I have tried putting global.RRCall and the scope of the application x_unoci_rapid_retu in the client script but to no avail, and I have also tried putting global in the 2nd line of the script include here RRcourseinfo.prototype = Object.extendsObject(global.AbstractAjaxProcessor,{

I continue to get the same error each time.

22 REPLIES 22

Thanks for sharing that. I have made a few changes to the script and it is listed below:

Client Script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

 if (isLoading || newValue == '') {
 return; 
}


var ga = new GlideAjax('RRcourseinfo');
 ga.addParam('sysparm_name', 'RRCall');
 ga.addParam('sysparm_x_unoci_rapid_retu_course_code', "");
 ga.getXML(RRCallParse);
 


 function RRCallParse(response) {

 var answer = response.responseXML.documentElement.getAttribute("answer"); 
 var obj = JSON.parse(answer);
 

g_form.setValue(x_unoci_rapid_retu_quarter,obj.quarterName);
g_form.setValue(x_unoci_rapid_retu_course_name,obj.name);
g_form.setValue(x_unoci_rapid_retu_total_students,obj.numStudents);
g_form.setValue(x_unoci_rapid_retu_quartershortcut,obj.qtr); 

	 
 }
 
}

 

Script Include:

var RRcourseinfo = Class.create();
RRcourseinfo.prototype = Object.extendsObject(global.AbstractAjaxProcessor,{

RRCall: function() {

var input = this.getParameter('sysparm_x_unoci_rapid_retu_course_code');
 
try { 
 var r = new sn_ws.RESTMessageV2('x_unoci_rapid_retu.EEE course information', 'Default GET');
 
r.setStringParameterNoEscape('Course Code', input);

var response = r.execute();
var requestBody = response.getBody();
var httpStatus = response.getStatusCode();

var obj = {};

var parsedResponse = JSON.parse(requestBody);

obj.quarterName = parsedResponse.qtrName;
obj.name = parsedResponse.name;
obj.numStudents = parsedResponse.numStudents;
obj.qtr = parsedResponse.qtr;


 var objString = JSON.stringify(obj);
 return objString;

}catch(ex) {

var message = ex.message;
gs.error(message);

}
 


 
 },


type: 'RRcourseinfo'
});

 

Several changes have been made to your script include but I have some additional questions. There are several parameters mentioned while making the REST call and setting the obj values that are not declared. Can you verify what the return body is when you are making the REST call? I've removed the following parameters as there were not defined.

obj.quarter = x_unoci_rapid_retu_quarter
obj.courseName = x_unoci_rapid_retu_course_name
obj.totalStudents = x_unoci_rapid_retu_total_students
obj.quarterShortcut = x_unoci_rapid_retu_quartershortcut

 

Also the Outbound REST you are calling is "x_unoci_rapid_retu.EEE course information" is that the actual name of the outbound message with "Course Code" as the proper HTTP Parameter? Also is it in the same scope as the client script and script include? If so you dont need to identify the scope in front of the REST Message name. Can simply be called like so:

var r = new sn_ws.RESTMessageV2('EEE course information', 'Default GET');

Hello David,

The rest message, client script and script include are all in the same scope application.  Those undefined variables are my attempt to capture and parse this return message that I expect to receive in JSON. Based on what course code is input different output will be received. My end goal is to pass them as objects to the client script to set them on the form.

{"status":"VALIDCCODE","qtr":"F18","qtrName":"Fall Qtr 2018","name":"TEST 99000 LEC A: E3 TOOLS (99000)","shortName":"TEST 99000  LEC A (99000)","deptName":"Test","numStudents":1}.

 

I tried the script changes you provided, I appear to still be running into the same blocked message. When the script triggers I get the message Access to script include RRCourse Info is blocked from scope x_unoci_rapid_retu. The java console tool I have up suggets that the http processor class is not found? I am very confused why scope is a problem when they are all created within and for the same application while also be set up to allow cross scope privileges.

Hmmm ok one more question..is "Client Callable" checked in your RRcourseinfo script include?

Yes sir it is and it is set to accessible from all application scopes just in case.

Ok so since the client script, script include, and REST Message are all in the same scope it is odd that you are receiving an access to scope error message. This leads me to think that RRCourseInfo script include is somehow not actually registered in the scope as expected. Can you attach screenshot of script include header information?

I appreciate you answering my questions as trying to troubleshoot items only by chat is sometimes difficult. 🙂