how to get the label names of checkbox (checked )

sainath3
Mega Guru

Hi Team,

Req:

In list of checkboxes need to get names of checkboxes wich are checked.

function onSubmit() {
//Type appropriate comment here, and begin script below

var one = g_form.getValue('one');
var two = g_form.getValue('two');
var three = g_form.getValue('three');
var four = g_form.getValue('four');
var five = g_form.getValue('five');
var gp = ' ';
var chv = [one, two, three, four, five];
var x;
for (x = 0; x < chv.length; x++) {

if (chv[x] == 'true') {
gp += (chv[x] + ',');
}
}
g_form.setValue('dis', gp);// here Out put is showing in form of true false,but i need checkboxes names,like one,two,three,four,five.
}

Help me out please,

 

Thanks!

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

it's not straight forward to get the labels

check this link for solution

How Can I get Label of Check Box Variable Label by Catalog Client Script?

OR

1) store a hidden variable with json structure like this

2) then parse the json in the onSubmit to get the checkbox labels for selected ones

{

"variableName1":"variable 1 label",

"variableName2":"variable 2 label",

}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader