- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2024 08:39 AM - edited 11-07-2024 08:43 AM
I have a multi-row variable set where each row has a checkbox.
It's possible to have multiple checkboxes selected (for example, 5 rows with 5 checkboxes selected).
How can I make sure that, when the form is submitted, no more than one checkbox is selected, and if more than one is selected, display an error message to the user?
Thanks
Matt
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2024 09:40 AM
Here's one way to check onSubmit of the request form, alerting and preventing submit if more than one row has the box checked.
function onSubmit() {
var checked = 'false';
var mrvs = JSON.parse(g_form.getValue('configuration_item_mrvs')); //MRVS internal name
for (var i = 0; i < mrvs.length; i++) {
if (mrvs[i].v_primary_mrvs == 'true') { //MRVS variable name
if (checked == 'false') {
checked = 'true';
} else {
alert ('More than one row has a box checked');
return false;
}
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2024 10:02 AM
Hello @Matt25
To enforce that only one checkbox is selected in a Multi-Row Variable Set (MRVS), you can add an onSubmit client script to the catalog item. This script counts the selected checkboxes when the form is submitted and shows an error message if more than one is selected, preventing submission.
Here's the script:
function onSubmit() {
var selectedCount = 0;
var mrvsRows = g_form.getValue('cmdb_ci'); //Mrvs variable set internal name
if (mrvsRows) {
var rows = JSON.parse(mrvsRows);
rows.forEach(function(row) {
if (row.check == 'true') { //here check is the checkbox variable name
selectedCount++;
}
});
}
if (selectedCount > 1) {
g_form.addErrorMessage("Only one checkbox can be selected. Please review your selections.");
return false; // Prevent form submission
}
return true; // Allow form submission
}I validated this solution in my Personal Developer Instance (PDI) to confirm that it functions as expected. This solution ensures that if multiple checkboxes were initially selected but then corrected to one, the form will pass validation.
"If you found my answer helpful, please give it a like and mark it as the accepted solution. It helps others find the solution more easily and supports the community!"
Thank You
Juhi Poddar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hi @Juhi Poddar
i facing multirow related one issue not able to solve please do needful see the steps below
1. I have catalog form Desktop -> i have multi single variables and one list collator variable type that is work_package
2. Same catalog i have multi row variable set 'selected_software_name_details ' in this MVRS i have 3 fields one is text field <work_package_names> and 2 check boxes 1. <Installation_completed> , 2. <varification_completed>
its displaying row and columms
3. List collator <work_package> have sys_choices (from business application custom field) using script included i have bring the data in this list collator --- > No issue here
4. Whatever i have selected work_package names that too displaying one by one row in text field of multi row variable and opposite check boxes also displayed with 'false' this is default values of check boxes in multi row variable set. ---- upto here working as expected
5. This Multi row variable set added only TASK2 here this MVRS displaying whatever i have submitted the record but check boxes displaying value with 'False' not showing TRUE whatever i have edited row and saved in MVRS.
I am stagging lot not able to solve this issue PDI also i am trying with simple logic but no use
if you know anyone help me in advance thank you
Regards,
PB
