Need the count of checked check boxes in service catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2023 10:55 AM
There are 8 check boxes under one label in service catalog.
I need to check if 1 check selected or more than 1 check box is selected.
If more than 1 check box is selected I need to display multiple string word in ritm short description.
Can any one provide script using array to acheive this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2023 02:11 AM
you can determine which checkboxes are checked in the run script.
something like this to make it dynamic
var arr = ['variable1','variable2','variable3','variable4','variable5','variable6','variable7','variable8'];
var str = '';
for(var i in arr){
if(current.variables[arr[i]].toString() == 'true'){
// concatenate the string variable
}
}
current.short_description = str;
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2023 05:10 AM
Hi ankur,
I need to check the count if more than 1 check box is checked I want to display multiply ministry in sd of ritm.
If one check box is selected that label need to be displayed in sd of ritm.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2023 05:17 AM
Here is a sample ServiceNow script that uses an array to check how many checkboxes are selected and to display multiple string words in the ritm short description if multiple checkboxes are selected:
// Get the selected checkboxes from the service catalog
var selectedChecks = [];
var checkLabels = ['Check Box 1', 'Check Box 2', 'Check Box 3', 'Check Box 4', 'Check Box 5', 'Check Box 6', 'Check Box 7', 'Check Box 8'];
for (var i = 0; i < checkLabels.length; i++) {
if (current.variables[checkLabels[i]] == true) {
selectedChecks.push(checkLabels[i]);
}
}
// Check how many checkboxes are selected
if (selectedChecks.length == 1) {
// Only one checkbox is selected, do nothing
} else if (selectedChecks.length > 1) {
// Multiple checkboxes are selected, concatenate their labels into a string
var selectedLabels = selectedChecks.join(', ');
current.short_description = "Multiple checkboxes selected: " + selectedLabels;
}
In this script, the selectedChecks array is populated by iterating through the checkbox labels and checking if their corresponding variables are set to true in the current object (which represents the current record being processed). The join method is then used to concatenate the selected checkbox labels into a single string, which is added to the ritm short description if more than one checkbox is selected.
If my answer solved your issue, please mark my answer as Correct & Helpful based on the Impact.
Thanks
Ravi Gaurav
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
YouTube: https://www.youtube.com/@learnservicenowwithravi
LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2023 05:18 AM
Here is a sample ServiceNow script that uses an array to check how many checkboxes are selected and to display multiple string words in the ritm short description if multiple checkboxes are selected:
// Get the selected checkboxes from the service catalog
var selectedChecks = [];
var checkLabels = ['Check Box 1', 'Check Box 2', 'Check Box 3', 'Check Box 4', 'Check Box 5', 'Check Box 6', 'Check Box 7', 'Check Box 8'];
for (var i = 0; i < checkLabels.length; i++) {
if (current.variables[checkLabels[i]] == true) {
selectedChecks.push(checkLabels[i]);
}
}
// Check how many checkboxes are selected
if (selectedChecks.length == 1) {
// Only one checkbox is selected, do nothing
} else if (selectedChecks.length > 1) {
// Multiple checkboxes are selected, concatenate their labels into a string
var selectedLabels = selectedChecks.join(', ');
current.short_description = "Multiple checkboxes selected: " + selectedLabels;
}
In this script, the selectedChecks array is populated by iterating through the checkbox labels and checking if their corresponding variables are set to true in the current object (which represents the current record being processed). The join method is then used to concatenate the selected checkbox labels into a single string, which is added to the ritm short description if more than one checkbox is selected.
If my answer solved your issue, please mark my answer as Correct & Helpful based on the Impact.
Thanks
Ravi Gaurav
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
YouTube: https://www.youtube.com/@learnservicenowwithravi
LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2023 07:14 AM
Hi Ravi,
I have tried but still not working as expected.