Comments on: Make Checkbox Variables Mandatory https://servicenowguru.com/client-scripts-scripting/checkbox-variables-mandatory/ ServiceNow Consulting Scripting Administration Development Thu, 07 Mar 2024 16:44:06 +0000 hourly 1 https://wordpress.org/?v=6.8.2 By: JJ Cortez https://servicenowguru.com/client-scripts-scripting/checkbox-variables-mandatory/#comment-8226 Thu, 31 May 2018 17:00:05 +0000 https://servicenowguru.wpengine.com/?p=3337#comment-8226 On my instance I had to declare var x in the for loop in order for the client script to execute. This was in a scoped app on version Jakarta patch 8a. Works great

Thanks Mark

]]>
By: Darrin Greene https://servicenowguru.com/client-scripts-scripting/checkbox-variables-mandatory/#comment-8225 Tue, 19 Dec 2017 17:43:11 +0000 https://servicenowguru.wpengine.com/?p=3337#comment-8225 Very helpful!!!

]]>
By: Mark Stanger https://servicenowguru.com/client-scripts-scripting/checkbox-variables-mandatory/#comment-8224 Mon, 08 May 2017 21:48:24 +0000 https://servicenowguru.wpengine.com/?p=3337#comment-8224 In reply to Jon Mulherin.

You’ll have to ensure that it is set correctly on change of each checkbox, but this should change the indicator for you.

mandatoryLabelName = ‘YOURLABELVARNAMEHERE’;
$(‘variable_’ + g_form.getControl(mandatoryLabelName).id).addClassName(‘is-filled’);

]]>
By: Jon Mulherin https://servicenowguru.com/client-scripts-scripting/checkbox-variables-mandatory/#comment-8223 Mon, 08 May 2017 19:46:31 +0000 https://servicenowguru.wpengine.com/?p=3337#comment-8223 Hi Mark,

The modified code to show the mandatory flag works great. Once a user selects one of the check boxes, how would you go about dimming the flag. Prior to the need to update the code after moving to Helsinki the following was working fine:

labels.previousSibling.className = ‘mandatory required-marker label_description’;
labels.up(‘table’).className=’question_spacer io_table is-filled’;

No so any longer. Any ideas?

]]>
By: John Vo https://servicenowguru.com/client-scripts-scripting/checkbox-variables-mandatory/#comment-8222 Thu, 23 Mar 2017 15:57:17 +0000 https://servicenowguru.wpengine.com/?p=3337#comment-8222 Mark I have 2 variables one is called Application which has 2 check boxes called wellview and siteview and the other is Request Training with 3 chec kboxes called new_user, group_class and specific_topic.

]]>
By: John Vo https://servicenowguru.com/client-scripts-scripting/checkbox-variables-mandatory/#comment-8221 Thu, 23 Mar 2017 15:17:11 +0000 https://servicenowguru.wpengine.com/?p=3337#comment-8221 Mark,

I pasted your script and still getting errors when selecting siteview and new_user, group_class or specific_topic. But it works when I select wellview with the other options.

function onSubmit(){
//Set the mandatory checkbox variable names and total mandatory count here
var mandatoryVars = ‘wellview, siteview, new_user, group_class, specific_topic’;
var mandatoryCount = 1;

var passed = forceMandatoryCheckboxes(mandatoryVars, mandatoryCount);
if(!passed){
//Abort the submit
alert(‘You must select at least ‘ + mandatoryCount + ‘ options.’);
return false;
}
}

function forceMandatoryCheckboxes(mandatory, count){
//Split the mandatory variable names into an array
mandatory = mandatory.split(‘,’);
var answer = false;
var varFound = false;
var numTrue = 0;
//Check each variable in the array
for(x=0;x= count){
answer = true;
break;
}
}
}
}
//If we didn’t find any of the variables allow the submit
if(varFound == false){
answer = true;
}
//Return true or false
return answer;
}

]]>
By: Mark Stanger https://servicenowguru.com/client-scripts-scripting/checkbox-variables-mandatory/#comment-8220 Thu, 23 Mar 2017 00:48:05 +0000 https://servicenowguru.wpengine.com/?p=3337#comment-8220 In reply to Denee Harris.

The script is working as designed but you need to modify the conditions where the script should apply. You’ll need to add those conditions into the client script so that it doesn’t run unless those conditions are met.

]]>
By: Denee Harris https://servicenowguru.com/client-scripts-scripting/checkbox-variables-mandatory/#comment-8219 Thu, 23 Mar 2017 00:38:03 +0000 https://servicenowguru.wpengine.com/?p=3337#comment-8219 Hello Mark

I have this code somewhat working. The only problem I am having is on my form the these fields are hiding unless you click “yes” to Catering. This is working fine. But if you select “No” the fields are hiding as expected and you click submit and the popup appears but it should only appear if Catering is Yes and No choices are selected.

Can you help, please

]]>
By: Mark Stanger https://servicenowguru.com/client-scripts-scripting/checkbox-variables-mandatory/#comment-8218 Wed, 22 Mar 2017 20:29:01 +0000 https://servicenowguru.wpengine.com/?p=3337#comment-8218 In reply to Greg Janicki.

It’s in the one for the mandatory label (along with an explanation that that piece won’t work in the Service Portal) but it isn’t in the one that actually forces mandatory checkboxes.

]]>
By: Greg Janicki https://servicenowguru.com/client-scripts-scripting/checkbox-variables-mandatory/#comment-8217 Wed, 22 Mar 2017 20:26:40 +0000 https://servicenowguru.wpengine.com/?p=3337#comment-8217 Hi Mark,

I am still having an issue with the ‘onSubmit’ script working within the Service Portal. Looks like ‘g_form.getControl’ is still in the script above?

Thanks for the help!!

]]>