- 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 01:54 AM
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
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2022 02:07 AM
Are your changes only in the following parts?
var ajax = new GlideAjax('getCurrentOperationSchedule');
It's the same value I had set when I posted this question, the result is the same.
Thanks for the confirmation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2022 02:19 AM
No
please try to paste the above code once again and try
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2022 02:41 AM
Thank you for the explanation. I copied and pasted the script you posted, but unfortunately it returned null as before.
Thank you for your advice.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2022 02:46 AM
Did you get a chance to check my below response?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader