I really need help with figuring out the logic to check for overlapping dates in an asset checkout.
Following scenario: I’ve got a Canvas App based on three SharePoint lists with the relevant columns:
- Assets (Title, Stock,...)
- Events (Title, StartDate, EndDate,..)
- AssetBooking (Title, Amount, Asset (LookUp), Event (LookUp),EventStart, EventEnd)
In my app I have a first screen where I choose the event in a gallery, which opens up the detail screen. There I can see all assets that are booked for this event. I have a button called “Add assets” which opens a popup with a ComboBox containing all assets.
If I choose an asset, I automatically want to check, how many assets are available during the time frame of the event. A slider control has the “max” property set to how many assets are available and then I can book the specified amount of assets.
What I tried is an OnChange on the ComboBox for the asset selection:
// OnChange property of the asset ComboBox control
Set(
assetSelected,
ComboBox2.Selected
);
ClearCollect(
overlappingBookings,
Filter(
AssetBooking,
Asset.Id = ComboBox2.Selected.ID &&
Event.Id <> eventSelected.ID &&
(DatePicker1.SelectedDate <= eventSelected.'End-Datum' &&
DatePicker1_1.SelectedDate >= eventSelected.'Beginn-Datum'))
);
Set(
totalBookedAssets,
Sum(
overlappingBookings,
Amount
)
);
Set(
maxAvailableAssets,
LookUp(
Assets,
Title = ComboBox2.Selected.Title
).Stock - Sum(
overlappingBookings,
Amount
)
);
If(
IsBlank(ComboBox2),
"",
If(
maxAvailableAssets < 1,
Notify(
"No assets available during the selected time",
NotificationType.Error
),
Notify(
maxAvailableAssets & " assets available during the selected time",
NotificationType.Success
)
)
)
I'm aware that this isn't correct, but I hope it manages to show where I'm trying to go.
I already had a look at these two threads:
Solved: Check if date overlaps with collection - Power Platform Community (microsoft.com)
Solved: Booking check against selected dates and time - Power Platform Community (microsoft.com)
but I still didn't manage to make it work. Time isn't important for me, just the date. But it's important to integrate the available stock logic.
I'd be so thankful if someone could help me with this one.