- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2019 03:10 PM
Hello Community,
I have a scoped application in which I have a Client Script and a Script Include.
The client script uses GlideAJAX to call the Script Include.
If I make the Script Include to be in the Global app, then I can get the data back into the Client Script.
But I get null when both the Client Script and the Script Include are in the scoped application.
I have run a background script on the Script Include and get data back. So I believe the issue is that the Client Script is not connecting to the Script Include. Any help would be very appreciated!
Here is my code:
Script Include:
var PFMUtilities = Class.create();
PFMUtilities.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
initialize: function() {
},
getPFMVersionInfo: function () {
var gr = new GlideRecord('x_mpii_pfm1_pfm_version_and_section_information');
gr.orderBy('pfm_version');
gr.query();
var PFMVersionARRAY = [];
while (gr.next()) {
PFMVersionARRAY.push ({
PFMVersion : gr.getValue('pfm_version'),
PFMVersionSysId : gr.getValue('sys_id')
});
}
var json = new JSON();
var data = json.encode(PFMVersionARRAY); //JSON formatted string
return data;
},
type: 'PFMUtilities'
});
The Client Script is:
function onLoad() {
// get the list of PFM Versions and Sections
// var ga = new GlideAjax('global.PFMUtilities'); // Script Include Name
var ga = new GlideAjax('PFMUtilities'); // Script Include Name
ga.addParam('sysparm_name', 'getPFMVersionInfo'); // function defined in the script include
ga.getXML(informationParse); // The function to parse the return values
}
function informationParse (response) {
g_form.addOption('PFMVersion', "", '--Select One--');
var answer = response.responseXML.documentElement.getAttribute("answer");
alert (answer);
answer = JSON.parse(answer);
for( var i = 0; i < answer.length ; i++) {
//Loop through array returned from Script Include
g_form.addOption('PFMVersion', answer[i].PFMVersionSysId, answer[i].PFMVersion);
}
}
Solved! Go to Solution.
- Labels:
-
Scoped App Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2019 06:26 PM
Good point David!
Try this code now:
var PFMUtilities = Class.create();
PFMUtilities.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
// Removed initialize function
getPFMVersionInfo: function () {
var gr = new GlideRecord('x_mpii_pfm1_pfm_version_and_section_information');
gr.orderBy('pfm_version');
gr.query();
var PFMVersionARRAY = [];
while (gr.next()) {
PFMVersionARRAY.push ({
PFMVersion : gr.getValue('pfm_version'),
PFMVersionSysId : gr.getValue('sys_id')
});
}
var json = new global.JSON(); //global prefix required in scope
var data = json.encode(PFMVersionARRAY); //JSON formatted string
return data;
},
type: 'PFMUtilities'
});
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2019 03:42 PM
Try using below client script
function onLoad() {
// get the list of PFM Versions and Sections
// var ga = new GlideAjax('global.PFMUtilities'); // Script Include Name
var ga = new GlideAjax('x_mpii_pfm1.PFMUtilities'); // Script Include Name
ga.addParam('sysparm_name', 'getPFMVersionInfo'); // function defined in the script include
ga.getXML(informationParse); // The function to parse the return values
}
function informationParse (response) {
g_form.addOption('PFMVersion', "", '--Select One--');
var answer = response.responseXML.documentElement.getAttribute("answer");
alert (answer);
answer = JSON.parse(answer);
for( var i = 0; i < answer.length ; i++) {
//Loop through array returned from Script Include
g_form.addOption('PFMVersion', answer[i].PFMVersionSysId, answer[i].PFMVersion);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2019 05:23 PM
Try removing your initialize function.
This might be overriding the AbstractAjaxProcessor constructor and causing the script to fail.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2019 05:40 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2019 06:26 PM
Good point David!
Try this code now:
var PFMUtilities = Class.create();
PFMUtilities.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
// Removed initialize function
getPFMVersionInfo: function () {
var gr = new GlideRecord('x_mpii_pfm1_pfm_version_and_section_information');
gr.orderBy('pfm_version');
gr.query();
var PFMVersionARRAY = [];
while (gr.next()) {
PFMVersionARRAY.push ({
PFMVersion : gr.getValue('pfm_version'),
PFMVersionSysId : gr.getValue('sys_id')
});
}
var json = new global.JSON(); //global prefix required in scope
var data = json.encode(PFMVersionARRAY); //JSON formatted string
return data;
},
type: 'PFMUtilities'
});
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022