- 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
‎07-09-2022 02:26 AM
I don't think it is documented. It is a global object hosting all sort of global client side data, like the current user, its roles, etc. In other words there wouldn't be much to document about it either. Cause it is just an object in the end, having a bunch of properties that contain data for stuff documented indirectly elsewhere - like g_user.hasRole.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2023 08:09 PM
Could you please share any documentation for global object NOW?
It would be great if you can provide any article related to that too. Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2023 10:37 PM
As already stated, as far as I know, there is not documentation or articles about the object.
I suppose it is meant to be a "safe" place where ServiceNow can store global stuff, data or even functionality, so that it does not conflict with global stuff of the browser.