How to create dependent variables in Multi row variable sets
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 03:19 AM
Hi All,
I have a requirement where I need to create 2 variables first is simple variable named test stockroom which is refeering to alm_stockroom table and second variable is MVRS test2 which includes one variable test asset that is referring to alm_asset table and as per the requirement the second variable value(multi row variable) will be dependent on the first variable value selected that means if I select test stockroom as ABC value then in the multirow varaible set variable in test asset i can see the only the asset related to ABC stockroom. Could anyone please suggest how to acheive this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 04:29 AM
Hi @Nitesh Kumar5 ,
Catalog Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// Make an AJAX call to get the filtered assets
var ga = new GlideAjax('GetAssetsByStockroom');
ga.addParam('sysparm_name', 'getAssets');
ga.addParam('sysparm_stockroom', newValue);
ga.getXMLAnswer(function(response) {
var assetList = response.split(',');
var mvrs = g_form.getValue('mvrs_test2');
for (var i = 0; i < mvrs.length; i++) {
var row = mvrs[i];
var test_asset = row.getValue('test_asset');
g_form.clearOptions('test_asset');
g_form.addOption('test_asset', '', '-- None --');
for (var j = 0; j < assetList.length; j++) {
g_form.addOption('test_asset', assetList[j], assetList[j]);
}
}
});
}
Script Include:
var GetAssetsByStockroom = Class.create();
GetAssetsByStockroom.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getAssets: function() {
var stockroom = this.getParameter('sysparm_stockroom');
var assetList = [];
var gr = new GlideRecord('alm_asset');
gr.addQuery('stockroom', stockroom);
gr.query();
while (gr.next()) {
assetList.push(gr.getValue('sys_id') + ',' + gr.getValue('name'));
}
return assetList.join(',');
}
});
If you find my response helpful, please consider marking it as the 'Accepted Solution' and giving it a 'Helpful' rating. Your feedback not only supports the community but also encourages me to continue providing valuable assistance.
Thanks,
Amitoj Wadhera