To add extra record in multirow variable set based on checkbox selection.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
I have a multirow variable set named pack_size.
when user add value in multirow variable set without clicking rho1 checkbox and clicks Add button. That selected record will gets added in the multirow variable set. Eg:
If user add values and selects rho1 , and clicks Add , we should get two records. One should be the user input record and another record should contains:
How can we implement this.
I tried with OnSubmit script in the multirow variable set, but SG01 - BT Singapore record is not getting inserted.
Sharing with the OnSubmit script :
function onSubmit() {
alert('onSubmit triggered');
// RH01 checkbox checked?
var rh01 = g_form.getValue('rho1');
alert('RH01 Value: ' + rh01);
if (rh01 != 'true') {
alert('RH01 not checked');
return true;
}
alert('RH01 checked');
// Parent MRVS name
var mrvsName = 'pack_size';
alert('MRVS Name: ' + mrvsName);
// Parent form
var parentForm = g_service_catalog.parent;
alert('Parent form accessed');
// Existing MRVS rows
var mrvsValue = parentForm.getValue(mrvsName);
alert('Existing MRVS Raw Value: ' + mrvsValue);
var rows = [];
if (mrvsValue) {
try {
rows = JSON.parse(mrvsValue);
alert('JSON parsed successfully');
alert('Existing Rows Count: ' + rows.length);
} catch (e) {
alert('JSON Parse Error: ' + e);
rows = [];
}
} else {
alert('MRVS is empty');
}
// Add SG01 row
rows.push({
sales_organisation_addpack: 'SG01 - BT Singapore',
distribution_channel_addpack: 'RH - Regional Hub',
plant_addpack: 'RH01 - Regional Hub Direct',
storage_location_addpack: '101 - RH Direct - GEN'
});
alert('SG01 row added');
alert('Updated Rows Count: ' + rows.length);
// Update MRVS
parentForm.setValue(
mrvsName,
JSON.stringify(rows)
);
alert('MRVS updated successfully');
return true;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
You may still be encountering an issue with what g_service_catalog.parent returns because it may remain stale throughout onChange as well which could mean behaviour is inconsistent or not as expected...
I think in order to get around that you would need to move the adding of the row to the catalog item itself rather than inside the MRVS. You would still run an onChange in the MRVS to set a hidden flag on the catalog item which would then trigger the adding of the additional row. The scripting would potentially change quite a bit depending on the exact business requirements such as if you just need one additional row if any record has RH01 = true or if you need to create an additional row for each record with RH01 = true.
I think the MRVS onChange script could be put directly on the actual RH01 variable to set the catalog flag which would greatly simplify that part of the script because you could use newValue === 'true'. Then the logic to add the new row(s) could be put directly in an onChange for the hidden flag trigger on the catalog item.