Ajax 401 (unauthorized) error when Client Script calls Script Include from the Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2022 10:58 AM
Hello Community. I have an issue with a Catalog Client Script and the Script Include the client script is calling via ajax from the Service Portal. The script works fine when I invoke it from a UI Action directly, however when calling from the Client side, I get the 401 error and nothing is returned to my callback. I have "Client Callable" selected on the Script Include and the class extends AbstractAjaxProcessor. Am I supposed to provide credentials with the Ajax call maybe? I noticed that the class initializer is being called, not sure if that's relevant.
Here is the actual error: GET https://ibmitsm.service-now.com/api/now/table/syntax_editor_macro?sysparm_fields=name%2Ctext 401 (Unauthorized)
Here are the scripts:
/* Catalog Client Script */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2022 11:16 AM
You should call it either in server side (with standart GlideRecord as in your AJAX) or do a direct HTTP request from the c;lient (in the widget )
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2022 02:05 PM
Thank you for responding, Joro. I found out that I had to add this to my class initializer:
initialize: function(request, responseXML, gc) {
global.AbstractAjaxProcessor.prototype.initialize.call(this, request, responseXML, gc);
},
After initializing the class I extended, it seems to work.
Update: from here: ref, I found this:
1. Delete the empty initialize function in your script include, as it will break the Abstract Ajax Processor.
Deleting the empty class initializer also worked.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2022 05:34 PM
Correct. Client callable Script Include does not have "initialize: function () {}" statement. This statement may exist in non-client callable Script Include.
The default template generated by ServiceNow when Client callable is checked won't generate this statement. When in doubt, it's always best to copy the function part, delete the entire script, re-generate the template.