- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2022 05:24 AM
Hello All,
I have written one catalog client script using g_scratchpad.
It is working on portal but on the backend side form.
Please let me know how can this be solved.
Script:
function onSubmit() {
var actionname = g_form.getActionName();
if (g_scratchpad.isSupportGroup) {
return true;
}
var val = g_form.getDisplayValue('datacity_service');
var ga = new GlideAjax("DataCityRequest");
ga.addParam("sysparm_name", "populateApplicationFields");
ga.getXML(populateApplicationFields);
return false;
function populateApplicationFields(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var obj = JSON.parse(answer);
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');
g_scratchpad.isSupportGroup = true;
} else if (PV_Customer_Request.indexOf(val) > -1) {
g_form.setValue('support_group', 'DWBI-Customer-Requests');
g_scratchpad.isSupportGroup = true;
} else if (PV_Operations_Request.indexOf(val) > -1) {
g_form.setValue('support_group', 'DWBI-Operations-Requests');
g_scratchpad.isSupportGroup = true;
} else {
g_form.setValue('support_group', 'ITDS-BI-REQUESTS');
g_scratchpad.isSupportGroup = true;
}
g_scratchpad.isSupportGroup = true;
g_form.submit(actionname);
} else {
g_form.setValue('support_group', 'ITDS-BI-REQUESTS');
g_scratchpad.isSupportGroup = true;
g_form.submit(actionname);
}
}
}
script Include:
var DataCityRequest = Class.create();
DataCityRequest.prototype = Object.extendsObject(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 05:57 AM
Actually, to make it as "safe" as possible, you may want to try a different approach: use g_scratchpad where available, else use NOW:
function onSubmit () {
var actionname = g_form.getActionName();
var scratchpad = g_scratchpad || NOW;
if (scratchpad.u_isSupportGroup) {
return true;
}
var val = g_form.getDisplayValue('datacity_service');
var ga = new GlideAjax("DataCityRequest");
ga.addParam("sysparm_name", "populateApplicationFields");
ga.getXML(populateApplicationFields);
return false;
function populateApplicationFields (response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var obj = JSON.parse(answer);
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.u_isSupportGroup = true;
}
else if (PV_Customer_Request.indexOf(val) > -1) {
g_form.setValue('support_group', 'DWBI-Customer-Requests');
scratchpad.u_isSupportGroup = true;
}
else if (PV_Operations_Request.indexOf(val) > -1) {
g_form.setValue('support_group', 'DWBI-Operations-Requests');
scratchpad.u_isSupportGroup = true;
}
else {
g_form.setValue('support_group', 'ITDS-BI-REQUESTS');
scratchpad.u_isSupportGroup = true;
}
scratchpad.u_isSupportGroup = true;
g_form.submit(actionname);
}
else {
g_form.setValue('support_group', 'ITDS-BI-REQUESTS');
scratchpad.u_isSupportGroup = true;
g_form.submit(actionname);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2022 06:53 AM
Hello Janos,
This is not getting the display value for val variable.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2022 08:50 AM
As said, getDisplayValue is not available in CMS. You need to switch the Catalog Client Script to work with values of datacity_service, not display values of the same.
Though if I were to do it, I'd move all logic server side and just return the assignment group and success/failure flag.
If all logic were to be moved to the server side (inside the Script Include), I could make use of Assignment Rules, Data Lookup Rules or Decision Tables to hold the logic of what assignment group to return under which condition.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2022 06:21 AM
One important thing to consider is whether the Catalog Item using this onSubmit script will be part of an Order Guide or not; if there is the slightest chance that it will be, you should make sure that the scratchpad is separated per Catalog Item:
var scratchpad = typeof g_scratchpad == 'undefined' ? getCatalogItemScratchpad(g_form.getUniqueValue()) : g_scratchpad;
// ...
function getCatalogItemScratchpad (catalogItemId) {
NOW.u_scratchpad = NOW.u_scratchpad || {};
NOW.u_scratchpad[catalogItemId] = NOW.u_scratchpad[catalogItemId] || {};
return NOW.u_scratchpad[catalogItemId];
}
Thus, if there are multiple Catalog Items in the Order Guide that are using this flag to control submission, the validation of one Catalog Item will not overflow into the validation of another Catalog Item.
Or just make sure the flag (isSupportGroup) is not used in any other onSubmit script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2022 06:40 AM
No it is not Order Guide.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2022 11:49 AM
Hi János,
Is the global object NOW documented anywhere? This seems really useful and I'd like to know more about it if possible.
Thank you.