How to get count of multiple selections made in multi select variable(List Collector type)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2023 01:21 AM
Hi,
I have a requirement to get the count of multiple selections made in the list collector variable on record producer form. Atleast i need to get if the selections are greater than one,,,, Could you please help ,me with the approach as i am stuck here...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2023 07:49 AM
Hi @yaminikoduri333 ,
You can achieve this with the Onchange client script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var listCollector = g_form.getControl('your_varaible_name_of_list_Collector'); // Get the list collector variable
var selectedOptions = listCollector.getSelectedOptions(); // Get the selected options from the list collector
var count = selectedOptions.length; // Get the length of the selected options array
// Check if the count is greater than one
if (count > 1) {
g_form.setValue('Your _varaible_name_setting_the_count',count);
}
}
Regards,
Shravan.
please mark it as helpful if this helps you and mark it as the correct solution which will help others as well
Shravan
Please mark this as helpful and correct answer, if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2023 06:37 PM
Hi @Sai Shravan,
Thank You for the kind response. I tried this and i am getting below error.
There is a JavaScript error in your browser console.
As per my requirement, I want to display a variable if the count of list collector variable selections is more than 1.
Could you please help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2023 08:07 PM
Hello @yaminikoduri333 ,
Can you please check the UI Type
If it is All , please change it UI Type = Desktop.
( There is a JavaScript error in your browser console. ) error will not come.
Please mark if it useful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2023 05:49 AM
@Sai Shravan @akin9 Thank You for the kind replies.
Finally From the reference of above suggestions i made it.
Below is the working approach.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var theValue = g_form.getDisplayValue('list_collector_field'); //newValue.toString();
var list = theValue.split(",");
var count = 0;
for (i = 0; i < list.length; i++) {
//g_form.addInfoMessage("This should be the list collector value " + list[i]);
count++;
}
if(count == 0 || count == 1){
g_form.setMandatory('variable_name2', false);
g_form.setDisplay('variable_name2', false);
//g_form.addInfoMessage('Count:'+count);
g_form.clearValue('u_priority');
}
if(count >= 2){
g_form.setDisplay('variable_name2', true);
g_form.setMandatory('variable_name2', true);
g_form.setValue('u_priority',1);
//g_form.addInfoMessage('Count:'+count);
}