- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2024 04:01 PM
Hello,
Here is my script include snippet and client contoller. I am getting the values printed correctly in script include, but gives Ajax error on client controller. Any help is appreciated
try{
var result = sn_fd.FlowAPI.executeAction('global.rest_api',inputs);
var url = result.url; // String
var statuscode = result.statuscode; // String
//window.open(url, '_blank');
gs.log("URL and Code " + url+ " ** "+statuscode);
return {
url: url,
statuscode :statuscode
};
} catch (ex) {
var message = ex.getMessage();
gs.error(message);
}
c.callSterling = function() {
c.data.requested_for = c.requestedFor.value;
c.data.requested_by = c.requestedBy.value;
alert(c.requestedFor.value+" @ "+c.data.requested_by);
var ga = new GlideAjax('global.scriptincludecall');
ga.addParam('sysparm_name', 'getRequestDetails');
ga.addParam('sysparm_req_for', c.requestedFor.value);
ga.addParam('sysparm_req_by', c.requestedBy.value);
ga.getXML(function (response ){
var respObj= JSON.parse(response.responseXML.documentElement.getAttribute('answer'));
var url= respObj.url;
var stat= respObj.statuscode;
alert(url+" "+stat);
});
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2024 10:36 PM
Hello @maryc
In script include, you are returning the object not the JSON string. First convert object to JSON string using JSON.stringify() and then return it.
You are already parsing the JSON in client so it should work.
On other hand, I assume you are writing this script in a Widget. If you want to run server side script, no need use GlideAjax as you can directly call server script in Client controller in widget. Checkout below article for more details:
https://serviceportal.io/communicating-between-the-client-script-and-the-server-script-of-a-widget/
Thank you,
Ali
Thank you,
Ali

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2024 10:36 PM
Hello @maryc
In script include, you are returning the object not the JSON string. First convert object to JSON string using JSON.stringify() and then return it.
You are already parsing the JSON in client so it should work.
On other hand, I assume you are writing this script in a Widget. If you want to run server side script, no need use GlideAjax as you can directly call server script in Client controller in widget. Checkout below article for more details:
https://serviceportal.io/communicating-between-the-client-script-and-the-server-script-of-a-widget/
Thank you,
Ali
Thank you,
Ali