- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2017 01:16 PM
Hi all,
Appreciate any help with this case:
I'm trying to get the labels from check boxes selected by user and display them on a multiple text box separated with a coma
I was trying to accomplish this with a run script with no results, I found this in another post(how to print the labels of True/False variables that are true on email templates? )
Not sure if I need an OnChange function or in the run script.
This is the original script from the other post
- template.print('<p>Environment Tiers:<br />');
- var fStr2 ='u_environment1,u_environment2'
- var fArr2 = fStr.split(',');
- for (x = 0; x < fArr2.length; x++) {
- if(current[fArr2[x]] != '') {
- var label = current[fArr2[x]].getLabel() + '<br />';
- template.print(label);
- }
- }
- template.print('</p>');
Best Regards
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
-
Team Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2017 10:55 AM
Based upon your example, it appears that you have a variable called Selected Options that should summarize the option checkboxes that are checked.
Probably the easiest way to accomplish what you are asking for is to use an onSubmit Catalog Client Script. This will check to see what checkboxes you have checked and list them in the Selected Options variable. For sample purposes, I will use the following Variable Questions and Names:
Option 1 [var_opt_1]
Option 2 [var_opt_2]
Option 3 [var_opt_3]
Selected Options [var_opt_selected]
Here is the Catalog Client Script Details:
Name: Set Selected Options onSubmit
Type: onSubmit
UI Type: All
Applies on a Catalog Item view: true
Script:
function onSubmit() {
var cb1 = (g_form.getValue('var_opt_1') == 'true');
var cb2 = (g_form.getValue('var_opt_2') == 'true');
var cb3 = (g_form.getValue('var_opt_3') == 'true');
var selectedTxt = '';
if (cb1) {
selectedTxt += 'Option 1\n';
}
if (cb2) {
selectedTxt += 'Option 2\n';
}
if (cb3) {
selectedTxt += 'Option 3\n';
}
g_form.setValue('var_opt_selected', selectedTxt);
}
Be sure to change the values of the variables to match whatever you have in your form.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2017 02:05 PM
That particular solution was for actual fields on a form and not for variables. This is mostly because it was for a record producer. Do you know if you are using a record producer, or a catalog item? If it is an actual catalog item, ServiceNow may have ways of getting at the selected values better than what was provided. There is an existing Notification email script that is used for this purpose that you can pull from called: requested_items_summary_with_options.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2017 10:16 AM
Hi Christopher,
Thanks for your support, this functionality is to be use in a catalog item, I got no experience at ServiceNow, trying to make my requirement clear, please check the below image
As you can see, it looks very simple, I just need to get the labels from the selected check boxes and display them into the "selected Options" field, it ´s just to gather that information separated with comas in one field, this is a requirement from user for report purpose and manage the information together , i.e:
Option 1, Option 2,Option 3;
If the 3 were checked
Hopefully this clarify what I'm trying to accomplish
Thanks
Best Regards

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2017 10:55 AM
Based upon your example, it appears that you have a variable called Selected Options that should summarize the option checkboxes that are checked.
Probably the easiest way to accomplish what you are asking for is to use an onSubmit Catalog Client Script. This will check to see what checkboxes you have checked and list them in the Selected Options variable. For sample purposes, I will use the following Variable Questions and Names:
Option 1 [var_opt_1]
Option 2 [var_opt_2]
Option 3 [var_opt_3]
Selected Options [var_opt_selected]
Here is the Catalog Client Script Details:
Name: Set Selected Options onSubmit
Type: onSubmit
UI Type: All
Applies on a Catalog Item view: true
Script:
function onSubmit() {
var cb1 = (g_form.getValue('var_opt_1') == 'true');
var cb2 = (g_form.getValue('var_opt_2') == 'true');
var cb3 = (g_form.getValue('var_opt_3') == 'true');
var selectedTxt = '';
if (cb1) {
selectedTxt += 'Option 1\n';
}
if (cb2) {
selectedTxt += 'Option 2\n';
}
if (cb3) {
selectedTxt += 'Option 3\n';
}
g_form.setValue('var_opt_selected', selectedTxt);
}
Be sure to change the values of the variables to match whatever you have in your form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2017 11:17 AM
Thanks a lot, this works as expected, exactly what I was looking for
Appreciate your help
Thanks