Prevent overlapping of entered time by the user.
Usecase: User wants to clock in his claims, and for this he has to lock in his time period for work on that claim. The system should validate if this timeperiod has already been entered by him or not, and hence prevents him/her for entering overlapping timeperiod claims.
Solution:
I tried various approaches to begin with, like saving a list with 24 fields each representing one hour. And then when claim was punched in the flow was to update the time period for that claim. This was just a basic solution and was rigid. Also it could not handle claims if the timeperiod was in hours and minutes like 1hr 30 mins for a claim.
So i needed something which was more dynamic and flexible in the approach. Also, i am a firm believer of the fact, that if something is incorrect the best solution is to refrain user from entering it inside the system. That way, you dont have to deal with fixing with it later. Yup i know i am lazy.
The below solution leverages collections. First i create a collection on submission of a claim.
The buttons like create col, copy and clear are used only for testing purpose and can be removed from the final solution.
colSelectedTimeSlots,
{
StartTime: Time(
Value(Dropdown1.SelectedText.Value),
Value(Dropdown1_1.SelectedText.Value),
0
),
EndTime: Time(
Value(Dropdown2.SelectedText.Value),
Value(Dropdown2_1.SelectedText.Value),
0
)
}
);
All this does is creates a collection colSelectedTimeSlots for the first time the user enters the claim, you can even move this code to Submit Claim.
Copy button is used to copy the collection to another collection. The onSelect property for this button says
Collect(colTemp,colSelectedTimeSlots);
Clear(colTemp); Clear(colSelectedTimeSlots);
We have a gallery where in we showing the data inside the main collection colSelectedTimeSlots.
What this code does is that it compares the clocked in values to the StartTime and EndTime values in the collection.
And if this is true that the value become 1 else it become 0. Now since this if sits pretty inside the ForAll so it loops across the items in collection and compares them to the claim entered timeperiod.
This then results in a table, to which we apply a countif condition. this gives us the count of records which result true for the comparasion.
And then we surround it with an if to check if its value >=1. If this is true, then we Disable the button for the user to submit the claim or else the display mode for this button is set to edit, so that user can submit his/her claim.
So, to cut long story short for a timeperiod which hasn't been registered previously for the claim this countif should return zero. Just like the below screenshot.
Happie PowerAppin!
Comments
Post a Comment