Check boxes set as true based on question choices.

Siva82
Tera Expert

Hi,

Now I am working catalog item, In catalog having 20+ check boxes .Based on question choices I need auto check(true) the check boxes.

For this I wrote client script. But  when I am selected question choice the only one check boxes. its first check box.As for attachement

But I wrote client scripts for 2 nd 3rd check boxes.

I need get auto check the based on script condition .

Can you refer attachments for reference 

Can you please help me on that.

find_real_file.png

find_real_file.png

Thank you.

7 REPLIES 7

Voona Rohila
Kilo Patron
Kilo Patron

Hi Siva

are the back-end names of your 2,3rd checkboxes correct in your client script?

Can you share the details of your checkboxe names.


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Hi Rohila,

Thank you for response,

Yes the back end names correct. Below onces are back end values of question.

 

field_sales_sales_rep

field_sales_inside_support

field_sales_administration.

 

Those 3 are back end values of question I need check (true) based question choice

 

Thank you

Yes you need to below code in your onchange client script

keep infomessage inside your if statement to check if the conditions are valid or not.

 

g_form.setValue('field_sales_sales_rep','true');

g_form.setValue('field_sales_inside_support','true');

g_form.setValue('field_sales_administration','true');

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Jan Cernocky
Tera Guru

Hi Siva,

your script on screenshot does not matches the fields you are also showing so it is a bit hard to debug. 

My remark - you're checking the "United states" but normally the getValue is returning the value, not the Label (or a sysID if it is a reference), so make sure the value is not something like "united_states". 

Additionally to debug it I would do something like this in the script (define variables separately so the condition then is easier to read and debug)

+ keep in mind to include the else branch to uncheck the checkboxes again in case the user select one option and then other so you don't get unexpected results

var isLocationCodeEmpty = g_form.getValue('please_select_the_location_code_UnitedStates') == '';
var isRequest1 = g_form.getValue('select_the_type_of_request') == '1';
var isCountryUS = g_form.getValue('please_select_the_country') == 'United States';

/* debug section
  g_form.addInfoMessage(isLocationCodeEmpty);
  g_form.addInfoMessage(isRequest1 );
  g_form.addInfoMessage(isCountryUS );
*/

if ((isLocationCodeEmpty && isRequest1) && isCountryUS) {
   g_form.setValue()
}