- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2022 12:47 AM
Hi Community,
I'm trying to call a script include from a catalog client script, but it doesn't work.
Some trials to investigate the cause and the results:
1. I changed the contents of the scripts to something very simple to investigate the cause, but the result is not returned.
2. I'm trying to spit out logs in the script include, but I don't see any logs. (Other script includes display the log, so you don't need to troubleshoot that part.)
3. The catalog client script itself is working fine, and "g_form.addInfoMessage" shows that null is returned from the script include.
Can anyone tell me what's wrong or detailed troubleshooting steps?
The following are the set values:
<Catalog Client Scripts>
Applies to: A Catalog Item
Active: True
UI Type: Mobile / Service Portal (The result is the same even if it is All)
Application: Global
Type: onChange
Applies on a Catalog Item view: True
<Script Include>
Name: getCurrentOperationSchedule
Application: Global
Accessible from: All application scopes
Client callable: True
Active: True
Protection policy: None
Below is the content of the scripts:
<Catalog Client Scripts>
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// var selectedWork = g_form.getValue('regular_work'); //commented out for investigation
var ajax = new GlideAjax('getCurrentOperationSchedule');
ajax.addParam('sysparm_name', 'showSchedule');
// ajax.addParam('sysparm_work', selectedWork); //commented out for investigation
ajax.getXML(displaySchedule);
function displaySchedule(response) {
var currentSchedule = response.responseXML.documentElement.getAttribute("answer");
g_form.addInfoMessage('The value is'+ currentSchedule); //returned message: The value is null
}
}
<Script Include>
var getCurrentOperationSchedule = Class.create();
getCurrentOperationSchedule.prototype = Object.extendsObject(AbstractAjaxProcessor, {
showSchedule: function() {
gs.info('Script Include getCurrentOperationSchedule Started');
// var selectedWork = this.getParameter('sysparm_work'); //commented out for investigation
return 'test';
},
type: 'getCurrentOperationSchedule'
});
I'm new to ServiceNow and JavaScript, so I expect easy-to-understand comments.
Thanks in advance,
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2022 06:41 PM
As you're on San Diego, client callable ACLs are created. Are you testing your script include as an admin or by impersonating a user?
Has the necessary ACL been created with a name of getCurrentOperationSchedule?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2022 02:21 AM
Hi,
update your client script as this and test once
use getXMLAnswer() instead of getXML()
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// var selectedWork = g_form.getValue('regular_work'); //commented out for investigation
var ajax = new GlideAjax('getCurrentOperationSchedule');
ajax.addParam('sysparm_name', 'showSchedule');
// ajax.addParam('sysparm_work', selectedWork); //commented out for investigation
ajax.getXMLAnswer(displaySchedule);
function displaySchedule(response) {
var currentSchedule = response;
g_form.addInfoMessage('The value is'+ currentSchedule); //returned message: The value is null
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2022 02:51 AM
Thank you for the advice. I replaced the target line but it returns null and I still don't see the following logs.
gs.info('Script Include getCurrentOperationSchedule Started');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2022 04:49 AM
Hi,
strange.
Did you try creating fresh script include with another name?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2022 06:02 PM
Thanks, I tried creating a new script include with a different name as your advice, but the result was the same.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2022 06:41 PM
As you're on San Diego, client callable ACLs are created. Are you testing your script include as an admin or by impersonating a user?
Has the necessary ACL been created with a name of getCurrentOperationSchedule?