How to auto populate a Multi row variable set on change of a field on catalog form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2024 07:36 AM
Hi Team ,
I have a multi row variable set on the Catalog item form. I created a reference field refering to request item table.
Whenever the user the selects the RITM number in the field (this will be the RITM number of the previous request) we should auto populate the MVRS values from that request number. For this I have written an OnChange catalog client script with Glide Ajax call and Script Include function.
Onchange script -
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var ritmNum = g_form.getValue('ritm_number_of_previous_request');
var gaRITM = new GlideAjax('global.XLSRowColumnValidation');
gaRITM.addParam('sysparm_name', 'getPrevRITMVariables');
gaRITM.addParam('sysparm_ritm', ritmNum);
gaRITM.getXML(handleResponse);
}
function handleResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('privilege_account_details1', answer);
}
Script Include func -
getPrevRITMVariables: function() {
var listValuename = [];
var ritmSysId = this.getParameter('sysparm_ritm');
var grRITM = new GlideRecord('sc_item_option_mtom');
grRITM.addEncodedQuery('request_item.sys_id=' + ritmSysId);
grRITM.query();
while (grRITM.next()) {
listValuename.push({
"accessGiven": grRITM.getValue('Access will be given to:'),
"email": grRITM.getValue('Email')
});
}
return JSON.stringify(listValuename);
},
Note - I observe that in that table glide recorded above 'sc_item_option_mtom' has empty values for the MVRS variables even though they are filled while submitting the form.
Please suggest if this is the correct approach. If not , Please help me with the code.
Thanks in Advance!!
Regards,
Pravallika K
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2024 07:41 AM
Hi @Pravallika1,
OnChange Catalog Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ritmNum = g_form.getValue('ritm_number_of_previous_request');
var gaRITM = new GlideAjax('global.GetPreviousRITMVariables');
gaRITM.addParam('sysparm_name', 'getPrevRITMVariables');
gaRITM.addParam('sysparm_ritm', ritmNum);
gaRITM.getXML(handleResponse);
}
function handleResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var values = JSON.parse(answer);
// Clear the MVRS before populating
g_form.clearValue('multi_row_variable_set_name');
// Loop through the values and add rows to the MVRS
values.forEach(function(row) {
var newRow = g_form.addRow('multi_row_variable_set_name');
g_form.setValue('multi_row_variable_set_name.access_given', row.accessGiven, newRow);
g_form.setValue('multi_row_variable_set_name.email', row.email, newRow);
});
}
Script Include:
var GetPreviousRITMVariables = Class.create();
GetPreviousRITMVariables.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getPrevRITMVariables: function() {
var ritmSysId = this.getParameter('sysparm_ritm');
var listValues = [];
var grRITM = new GlideRecord('sc_item_option');
grRITM.addEncodedQuery('request_item.sys_id=' + ritmSysId);
grRITM.query();
while (grRITM.next()) {
listValues.push({
"accessGiven": grRITM.getValue('variable_name_for_access_given'),
"email": grRITM.getValue('variable_name_for_email')
});
}
return JSON.stringify(listValues);
},
type: 'GetPreviousRITMVariables'
});
Thank you, please make helpful if you accept the solution.