Setting the value of a Catalog Variable outside an MRVS based on the number of rows in the MRVS
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
I recently had a requirement to populate a catalog variable outside a Multi-Row Variable Set (MRVS) based on the number of rows entered by the user.
Requirement
- MRVS: equipment_details
- Hidden catalog variable: devicescount
- Update the hidden variable whenever rows are added or removed from the MRVS.
- Exclude rows where the Device Type (device_type) is "SIM Only" from the count.
Since there isn't a native onChange event for an MRVS in Employee Center, used an onLoad Catalog Client Script that periodically checks the MRVS for changes and updates the hidden variable only when the count changes.
Hopefully this helps anyone with a similar requirement.
function onLoad() {
var previousCount = -1;
setInterval(function() {
var count = 0;
try {
var rows = JSON.parse(g_form.getValue('equipment_details'));
for (var i = 0; i < rows.length; i++) {
// Exclude SIM Only devices from the count
if (rows[i].device_type!== 'SIM Only') {
count++;
}
}
} catch (e) {
count = 0;
}
if (count !== previousCount) {
previousCount = count;
g_form.setValue('devicescount', count);
}
}, 500);
}
Notes:
- This solution was implemented in Employee Center.
- device_typeis the internal name of the MRVS variable containing the device type.
- devicescount is a hidden catalog variable outside the MRVS.
- If your choice field stores a value different from the display label (for example, sim_only instead of SIM Only), update the comparison accordingly.
I hope this saves someone some time. If you have a cleaner approach for handling MRVS row count changes in Employee Center, I'd be interested to hear it.
0 REPLIES 0