Adding multiple values to a multi-row variable set
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2024 10:37 AM
I have a catalog item where I'm populating a list collector with values on selection of a checkbox. (Consider these are groups that the user is a part of). This part is working fine. Now, on change of the same checkbox, I want to populate a Multi Row variable set instead of the list collector. And I need all the values to be populated. How can this be done in a client script? The script include and returned values are working as expected, I need to just modify the client script if possible. Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2024 10:46 AM
You can set the value of a MRVS using g_form.setValue('mrvs_internal_name'). The value in this case needs to be a JSON formatted string containing name value pairs where name = the mrvs variable name, and value = what you want to populate. Do you have multiple checkboxes, and checking each one should create a new row in the MRVS, or update an existing row?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2024 09:27 PM
I have a single checkbox but I need to add say 5 rows to the MRVS by checking one checkbox. Is that possible?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2024 06:46 AM
In this code example, I have a checkbox variable at the Catalog Item-level named check_var, an MRVS with an internal name = user_mrvs, and two variables within the MRVS named v_group, which is a reference, and v_text which is a single line text. In the simplest use case, onChange of check_var I can populate the MRVS like this:
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == 'true') {
var obj = JSON.parse(g_form.getValue('user_mrvs'));
obj.push({
v_group: 'b8ef24616fc331003b3c498f5d3ee434',
v_text: ''
});
g_form.setValue("user_mrvs", JSON.stringify(obj));
}
}
Here I am adding one row in the MRVS to any existing rows, and not populating anything in the text variable. You can add as many rows as needed in a loop or with multiple pushes to the obj array.