How to merge two GlideAjax calls onLoad into one
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
I've got two functions within my script include:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
What is your business requirement. Please explain.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
I'm wanting to combine both glideAjaxes gaExistingConsumers and gaConsumedGroudWide into one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Instead of firing two separate GlideAjax calls, pass all parameters at once to a single script include and parse the returned JSON.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
try this
Script Include:
getBusinessAppData: function() {
var busApp = this.getParameter('sysparm_app');
var response = {
gw_check: false,
consumer_orgs: []
};
var grBusinessApp = new GlideRecord('cmdb_ci_business_app');
if (grBusinessApp.get(busApp)) {
response.gw_check = grBusinessApp.getValue('u_consumed_group_wide') == 'true';
}
var viewedDepartments = {};
var grConsumerRecordEntries = new GlideRecord('u_m2m_depts_config_items');
grConsumerRecordEntries.addQuery('u_configuration_item', busApp);
grConsumerRecordEntries.addNotNullQuery('u_department');
grConsumerRecordEntries.query();
while (grConsumerRecordEntries.next()) {
var departmentSysId = grConsumerRecordEntries.getValue('u_department');
if (viewedDepartments[departmentSysId]) {
continue;
}
viewedDepartments[departmentSysId] = true;
var grDepartmentRecord = new GlideRecord('cmn_department');
if (!grDepartmentRecord.get(departmentSysId)) {
continue;
}
var departmentID = grDepartmentRecord.getValue('id');
var parent = grDepartmentRecord.getValue('parent');
var businessUnitFunction = departmentSysId;
if (parent) {
var grParentTypeCheck = new GlideRecord('cmn_department');
if (grParentTypeCheck.get(parent)) {
var parentDepartmentType = grParentTypeCheck.getValue('u_department_type');
var parentIsBusinessUnit = grParentTypeCheck.getValue('u_business_unit') == 'true';
if (parentDepartmentType == 'Business Unit' || parentDepartmentType == 'Function' || parentIsBusinessUnit) {
businessUnitFunction = parent.toString();
}
}
}
response.consumer_orgs.push({
consumer_organisation_id: departmentID,
consumer_organisation: departmentSysId,
business_unit_function: businessUnitFunction
});
}
return JSON.stringify(response);
},
Client Script
function onLoad() {
var objData = _getBusinessApplicationIDFromURL(top.location.href);
if (objData.success == true) {
var strBusinessApplicationSysID = objData.sys_id;
g_form.setValue('business_application', strBusinessApplicationSysID);
var gaBusinessAppData = new GlideAjax('LBGConsumOrgsCatItem');
gaBusinessAppData.addParam('sysparm_name', 'getBusinessAppData');
gaBusinessAppData.addParam('sysparm_app', g_form.getValue('business_application'));
gaBusinessAppData.getXML(handleBusinessAppData);
} else {
g_form.addErrorMessage('Unfortunately this catalogue item has not loaded correctly and as a result will not work. Please try again');
}
}
function handleBusinessAppData(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
if (!answer) {
return;
}
var data = JSON.parse(answer);
g_form.setValue('consumer_orgs_list', JSON.stringify(data.consumer_orgs));
g_form.clearValue('business_unit_function');
g_form.clearValue('consumer_organisation');
g_form.clearValue('consumer_organisation_id');
g_form.clearValue('selected_option');
if (data.gw_check) {
g_form.setValue('selected_option', 'option_1');
g_form.setReadOnly('selected_option', true);
g_form.setValue('is_group_wide', true);
g_form.addInfoMessage("This application is currently defined as being consumed group wide (i.e. supporting all business units, and group functions). If updated to support specific business areas then it will no longer be defined as 'Consumed Group Wide' and the existing relationships to all business units and group functions will be removed and replaced by the specific business areas selected below.");
} else {
g_form.setReadOnly('selected_option', false);
g_form.clearValue('selected_option');
g_form.setValue('is_group_wide', false);
}
}
💡 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