I have a multi-select combobox that provides data for a couple different functions. In one function I need to add each selected item in the combobox to it's own row in a collection, along with other data. The multi-select function is necessary for app usability.
I do have a formula that will create the individual rows, but it creates multiple instances of each row.
The Comboxbox items are a collection of regions. The collection is cleared and repopulated each time a different country is selected as shown below. Multiple Holidays are added to the Holiday collection for the same country, but the regions for each specific holiday will vary. For the examples below I have just used all the regions.
ClearCollect(RegionsColl,
ShowColumns(
Filter(Regions, Country.Name in DropdownCountry.Selected.Name And "Yes" in Active),
"crc39_name"
));
Brazil
Canada
This is the formula that adds the Combobox items to the collection
If(
CountRows(ComboBoxRegion.SelectedItems) >0 && CountIf(EventIndex, Region in ComboBoxRegion.SelectedItems.crc39_name && HolidayName in LabelHolidayNameCombined) = 0,
Collect(EventIndex,
ForAll(ComboBoxRegion.SelectedItems As _item,
{Region: _item.crc39_name,
Date:Text(DatePickerHolidayDate.Value),
Country: DropdownCountry.Selected.Name,
HolidayName: LabelHolidayNameCombined.Text
}
),
Collect(EventIndex,
{Date:Text(DatePickerHolidayDate.Value),
Country: DropdownCountry.Selected.Name,
HolidayName: LabelHolidayNameCombined.Text
}
)
)
);
When this runs it adds each row twice. Every time it runs after the first time, the new items are added AND each previous entry is added again (twice) even if the Regions collection no longer contains the same regions.
1st Run: 2 sets of entries (2 rows for each region and 2 blank rows)
2nd Run: 2 sets for the newly selected regions, 4 sets for the originally selected regions
3rd Run: 2 sets for the newly selected regions, 4 sets for the regions selected in the 2 run and 6 sets for the regions selected in the 1st run.
Here are screenshots. For the 2nd image I have removed the blank rows so you can see what is happening more easily
Solved! Go to Solution.
So, the formula didn't give me any errors or indicators (red squigglies) that something wasn't right and worked but not correctly. The solution? Add an additional close paren at the end of the first If action.
If(
CountRows(ComboBoxRegion.SelectedItems) >0 && CountIf(EventIndex, Region in ComboBoxRegion.SelectedItems.crc39_name && HolidayName in LabelHolidayNameCombined) = 0,
Collect(EventIndex,
ForAll(ComboBoxRegion.SelectedItems As _item,
{Region: _item.crc39_name,
Date:Text(DatePickerHolidayDate.Value),
Country: DropdownCountry.Selected.Name,
HolidayName: LabelHolidayNameCombined.Text
}
)
),
Collect(EventIndex,
{Date:Text(DatePickerHolidayDate.Value),
Country: DropdownCountry.Selected.Name,
HolidayName: LabelHolidayNameCombined.Text
}
)
)
);
Hi @JR-BejeweledOne,
Do you have code somewhere in your logic that is clearing the ComboBoxRegion.SelectedItems when the country changes? This might be a stupid question but I don't see where this is cleared so as you add more items it is going to include the items you had selected in the past as well so continue to duplicate every time. Just a thought...
Thanks,
Drew
The ComboBox items is a collection. The issue occurs regardless if the country is changed.
OnChange formula for the country dropdown:
ClearCollect(RegionsColl,
ShowColumns(
Filter(Regions, Country.Name in DropdownCountry.Selected.Name And "Yes" in Active),
"crc39_name"
));
So, the formula didn't give me any errors or indicators (red squigglies) that something wasn't right and worked but not correctly. The solution? Add an additional close paren at the end of the first If action.
If(
CountRows(ComboBoxRegion.SelectedItems) >0 && CountIf(EventIndex, Region in ComboBoxRegion.SelectedItems.crc39_name && HolidayName in LabelHolidayNameCombined) = 0,
Collect(EventIndex,
ForAll(ComboBoxRegion.SelectedItems As _item,
{Region: _item.crc39_name,
Date:Text(DatePickerHolidayDate.Value),
Country: DropdownCountry.Selected.Name,
HolidayName: LabelHolidayNameCombined.Text
}
)
),
Collect(EventIndex,
{Date:Text(DatePickerHolidayDate.Value),
Country: DropdownCountry.Selected.Name,
HolidayName: LabelHolidayNameCombined.Text
}
)
)
);
User | Count |
---|---|
20 | |
10 | |
9 | |
5 | |
5 |
User | Count |
---|---|
32 | |
30 | |
18 | |
17 | |
7 |