- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2023 12:34 AM
Hello all
I have more then 50 checkbox in my catalog items.. Among this 50 checkbox only the selected values must be shown in the multiline text.
My below code is not working, I'm testing it with 3 checkbox in the below script.. Please help me here
function onSubmit() {
var v1 = g_form.getValue('check1');
var v2 = g_form.getValue('check2');
var v3 = g_form.getValue('check3');
var arr = [v1, v2, v3];
var arr2 = [];
for (var i in arr) {
if (arr[i] == true) {
arr2.push(arr[i]);
g_form.setValue('check_box_values', arr2);
}
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2023 12:39 AM
@David Cross can you try (arr[i] == 'true') i.e. true as string instead of Boolean once and see if that makes it work.
Best regards
Suyog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2023 12:39 AM
@David Cross can you try (arr[i] == 'true') i.e. true as string instead of Boolean once and see if that makes it work.
Best regards
Suyog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2023 12:43 AM - edited 10-23-2023 12:43 AM
Thank You Suyog, This worked;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2023 12:42 AM
Hi @David Cross ,
Can u try below code:
function onSubmit() {
var v1 = g_form.getValue('check1');
var v2 = g_form.getValue('check2');
var v3 = g_form.getValue('check3');
var arr = [];
if (v1) {
arr.push('Check 1 Label or Value'); // Replace 'Check 1 Label or Value' with the actual label or value of the checkbox
}
if (v2) {
arr.push('Check 2 Label or Value'); // Replace 'Check 2 Label or Value' with the actual label or value of the checkbox
}
if (v3) {
arr.push('Check 3 Label or Value'); // Replace 'Check 3 Label or Value' with the actual label or value of the checkbox
}
var multilineText = arr.join('\n'); // Join the array elements with newline characters
g_form.setValue('check_box_value
s', multilineText);
}
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2023 12:43 AM
Hi @David Cross
Try like below :
function onSubmit() {
var v1 = g_form.getValue('check1');
var v2 = g_form.getValue('check2');
var v3 = g_form.getValue('check3');
var arr = [v1, v2, v3];
var arr2 = [];
for (var i in arr) {
if (arr[i] == true) {
arr2.push(arr[i]);
}
}
g_form.setValue('check_box_values', arr2.toString()); //set the value after for loop
}
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates