Client Script setting a checkbox to true is not working

Jazz5
Kilo Expert

Hello all,

I have multiple choice field, with three choices.  The following client script does not seem to work. I want to set a checkbox to true depending on the multiple choice selected on the catalog item,

Type is onchange

 

find_real_file.png

find_real_file.png

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

if (newValue == 'OTC') {
g_form.setValue('otc_lm_cash', 'true');
}

else if (newValue == 'RTR') {
g_form.setValue('rtr_icrecon', 'true'); g_form.setValue('rtr_lm_cash', 'true');
}

else if (newValue == 'PTP') {
g_form.setValue('payment_processing', 'true');
}
}

14 REPLIES 14

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Have you debugged that the Catalog Client Script is triggered at all?

If this is on the Service Portal, make sure the UI Type of the Catalog Client Script is set to "All".

Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 ServiceNow Developer MVP

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

I have not use debugging before so not sure how to do this. 

Client Script is set to 'All' and I have removed the quotes around true and this still does not work. 

shloke04
Kilo Patron

Hi,

Quotes is not required while setting checkbox value as true. Plesae use the modified script as below:

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

if (newValue == 'OTC') {
g_form.setValue('otc_lm_cash', true);
}

else if (newValue == 'RTR') {
g_form.setValue('rtr_icrecon', true);
 g_form.setValue('rtr_lm_cash', true);
}

else if (newValue == 'PTP') {
g_form.setValue('payment_processing', true);
}
}
Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Also if the above script does not work, can you put a alert  to see in which block of code the script is executing or failing.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke