✅ When navigating away and back, the checkboxes must stay as previously selected
✅ User can continue where they left off (no reset, no lost progress)

UpdateContext({_selectedItem:ThisItem});
//This will help us to update the item when the click on checkbox
With(
{
cleaned: Substitute(Substitute(Substitute(Substitute(uplift.Text, ",", " "), Char(10), " "), Char(13), " "), Char(9), " ")
},
ClearCollect(
colMealItems,
ForAll(
MatchAll(cleaned, "(?i)\b\d+\s*[A-Z]{4}\b"),
{
MealName: Upper(Substitute(ThisRecord.FullMatch, " ", "")),
IsChecked: !IsBlank(LookUp(ThisItem.'Selected SPML', MealName = Upper(Substitute(ThisRecord.FullMatch, " ", ""))))
}
)
)
)
ThisItem.MealName in colMealItems.MealName
// Update the local collection
UpdateIf(
colMealItems,
MealName = ThisItem.MealName,
{ IsChecked: chkMeal.Value }
);
// Patch immediately to Dataverse
Patch(
BeltPlanAutomated,
_selectedItem,
{
'Selected SPML': Coalesce(
Concat(
Filter(colMealItems, IsChecked),
MealName,
", "
),
"None"
)
}
)