GlideAjax not calling Script Include on Catalog Item submit (Service Portal)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi all,
I’m facing an issue while trying to create a Hardware Disposal Order from a Catalog Item (Service Portal / Employee Center) using GlideAjax, and I’m hoping for guidance on the correct approach.
Requirement
On catalog item submission, create a record in sn_hamp_hardware_disposal
Pass values like Stockroom and Location from the form
Use a Script Include (AbstractAjaxProcessor) to handle record creation
What I Implemented
Created a Client Callable Script Include in the sn_hamp scope extending AbstractAjaxProcessor
Calling it from a Catalog Client Script (onSubmit) using GlideAjax
client script
function onSubmit() {
var ga = new GlideAjax('QuestHardwareDisposalOrder');
ga.addParam('sysparm_name', 'createDisposalOrder');
ga.addParam('sysparm_stockroom', g_form.getValue('select_stockroom'));
ga.getXMLAnswer(function() {
g_form.submit();
});
return false;
}
script include
Issue
The catalog item submits successfully
But the Script Include is not called
No logs appear (gs.info does not log)
No record is created in sn_hamp_hardware_disposal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
why you want record to be inserted during form submission?
Not a good idea and I won't recommend from best practice point of view
Why not use Flow on that catalog item and then create record into table after RITM/REQ is generated?
This is more consistent and can happen without script include and no-code approach
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Is your script include glideajax enabled? Either way you should look into having this logic in the flow not in the client
On another note take into account that getxmlanswer is asynchronous and you might get some unexpected behaviour if you do something with the response. The g_form.submit() also should not be there in the callback.
Couple of tips for writing script includes too:
- Create a public method for retrieving the parameters, which will then call the private method the logic. This way you can test the server side logic from a bg script easily.
- You can call glideajax from console in the browser devtools making it easier then to validate the glideajax script before you validate the whole client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
The issue may be due to the getXMLAnswer() as it is Asynchronous call which return false is not gonna work.Please check the below article
https://www.servicenow.com/community/developer-articles/getxmlwait-alternative-for-service-portal/ta...
The best approach is go with the flow designer .
Hope that Helps!
