- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2022 08:54 AM
Hello All,
I have written a catalog client script and script include nut getting an error message.
There is a JavaScript error in your browser console
Unhandled exception in GlideAjax in Service Portal
Please let me know how can I solve this.
Client script :
function onSubmit () {
var actionname = g_form.getActionName();
var scratchpad = typeof g_scratchpad == 'undefined' ? NOW : g_scratchpad;
if (scratchpad.isSupportGroup) {
return true;
}
var val = g_form.getValue('datacity_service');
var ga = new GlideAjax('DataCityRequest');
ga.addParam('sysparm_name', 'populateApplicationFields');
ga.getXMLAnswer(populateApplicationFields);
return false;
function populateApplicationFields(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
var obj = answer.evalJSON(true);
var PV_Corporate_Request = obj.property1.split(",");
var PV_Customer_Request = obj.property2.split(",");
var PV_Operations_Request = obj.property3.split(",");
var AppropriateCategory = g_form.getValue('appropriate_category');
if ((AppropriateCategory == 'Request Enhancement') || (AppropriateCategory == 'SME-Project Estimates') || (AppropriateCategory == 'Report Defect')) {
if (PV_Corporate_Request.indexOf(val) > -1) {
g_form.setValue('support_group', 'DWBI-Corporate-Requests');
scratchpad.isSupportGroup = true;
}
else if (PV_Customer_Request.indexOf(val) > -1) {
g_form.setValue('support_group', 'DWBI-Customer-Requests');
scratchpad.isSupportGroup = true;
}
else if (PV_Operations_Request.indexOf(val) > -1) {
g_form.setValue('support_group', 'DWBI-Operations-Requests');
scratchpad.isSupportGroup = true;
}
else {
g_form.setValue('support_group', 'ITDS-BI-REQUESTS');
scratchpad.isSupportGroup = true;
}
scratchpad.isSupportGroup = true;
g_form.orderNow(actionname);
}
else {
g_form.setValue('support_group', 'ITDS-BI-REQUESTS');
scratchpad.isSupportGroup = true;
g_form.orderNow(actionname);
}
}
}
script include:
var DataCityRequest = Class.create();
DataCityRequest.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
populateApplicationFields: function() {
var obj = {};
obj.property1 = gs.getProperty("Datacity Request - DWBI-Corporate-Requests");
obj.property2 = gs.getProperty("Datacity Request - DWBI-Customer-Requests");
obj.property3 = gs.getProperty("Datacity Request - DWBI-Operations-Requests");
return JSON.stringify(obj);
},
type: 'DataCityRequest'
});
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2022 10:53 AM
Yeah, me silly, the reference to the function(s) need to be "bound" as below:
var submitMethod = typeof g_form.orderNow == 'function' ? g_form.orderNow.bind(g_form) : g_form.submit.bind(g_form);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2022 09:35 AM
Further looking into your script, I see that another problem is the g_form.orderNow() method: it is only supported in CMS. Substitute g_form.submit() for it. Also action name is not necessary, it is not like you can have multiple submit buttons on a Catalog Item anyway.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2022 10:17 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2022 10:30 AM
Well, that basically means that you have to create two onSubmit Catalog Client Scripts :-(. One that will have UI Type = All (or = Mobile / Service Portal) and another that will have UI Type = Desktop. The 1st one will utilize the submit() method (so that it works in Portal) while the 2nd one will utilize orderNow() method so that it will works in CMS.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2022 10:38 AM
On the other hand one could use a reference to the correct function - similar to how a reference to a scratchpad has been created:
function onSubmit () {
var actionname = g_form.getActionName();
var scratchpad = typeof g_scratchpad == 'undefined' ? NOW : g_scratchpad;
var submitMethod = typeof g_form.orderNow == 'function' ? g_form.orderNow : g_form.submit;
if (scratchpad.isSupportGroup) {
return true;
}
...
Later when submit is needed:
...
scratchpad.isSupportGroup = true;
submitMethod(actionname);
}
else {
g_form.setValue('support_group', 'ITDS-BI-REQUESTS');
scratchpad.isSupportGroup = true;
submitMethod(actionname);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2022 10:42 AM
Hello Janos,
Still not working.