- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2020 12:36 AM
Hi all,
We created a variable set in a catalog item with 6 Variables.
In that variable set 2 variables are label type fields.
And 4 variables are check box types.
Requirement is to select at least one check box from the list of 4 checkbox variables before request submission. if no checkbox variable is marked as true, then we need to restrict the user for submitting the form by giving an alert.
Please help me with the script which we need to use for achieving this.
Thank you,
Raja.
Solved! Go to Solution.
- Labels:
-
Request Management
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2020 12:46 AM
you need to use onSubmit catalog client script for this
Applies to Catalog Item - true
Applies on Catalog Item view - true
sample below
function onSubmit(){
var allowed = 'false';
// give here the 4 variable names in array
var checkboxArray = ['variableName1','variableName2','variableName3','variableName4'];
for(var i=0;i<checkboxArray.length;i++){
if(g_form.getValue(checkboxArray[i]).toString() == 'true'){
allowed = 'true';
break;
}
}
if(allowed == 'false'){
alert('Atleast 1 checkbox is to be selected');
return false;
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2020 12:45 AM
Refer below code,
Add field names as per your requirement,
if(g_form.getValue(field_name1) == 'true' ) || g_form.getValue(field_name2) == 'true' ) || g_form.getValue(field_name3) == 'true' ) || g_form.getValue(field_name4) == 'true' ))
{
return true
}
else
{
alert('Please be sure to check the box before submitting a form.');
return false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2020 12:46 AM
you need to use onSubmit catalog client script for this
Applies to Catalog Item - true
Applies on Catalog Item view - true
sample below
function onSubmit(){
var allowed = 'false';
// give here the 4 variable names in array
var checkboxArray = ['variableName1','variableName2','variableName3','variableName4'];
for(var i=0;i<checkboxArray.length;i++){
if(g_form.getValue(checkboxArray[i]).toString() == 'true'){
allowed = 'true';
break;
}
}
if(allowed == 'false'){
alert('Atleast 1 checkbox is to be selected');
return false;
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader