While entering a leave request in a read-only grid I am entering the same date two times with different leave type (which is allowed). I need to get the leave hours entered for the same date as I need to give a validation message if the sum of leave hours exceed 8 hrs for the same day. How can I achieve this?
In the sample data given below, I want to extract the requested hours where the leave dates are same:
[LAST_UPD_USR:ehelen,LAST_UPD_TS:10/14/2022 5:55 AM GMT,CREATE_USR:ehelen,CREATE_TS:10/14/2022 5:53 AM GMT,IS_ACTIVE:true,APPROVED_HRS:,REQUESTED_HRS:5,LEAVE_TYPE:Sick Leave,LEAVE_DATE:10/26/2022,FK_STAFF_ID:113,FK_EMPLOYEE_LEAVE_REQUEST_ID:19,EMPLOYEE_LEAVE_REQUEST_DETAILS_ID:1];
[LAST_UPD_USR:ehelen,LAST_UPD_TS:10/14/2022 5:55 AM GMT,CREATE_USR:ehelen,CREATE_TS:10/14/2022 5:53 AM GMT,IS_ACTIVE:true,APPROVED_HRS:,REQUESTED_HRS:8,LEAVE_TYPE:Vacation Leave,LEAVE_DATE:10/20/2022,FK_STAFF_ID:113,FK_EMPLOYEE_LEAVE_REQUEST_ID:19,EMPLOYEE_LEAVE_REQUEST_DETAILS_ID:2]
Thanks,
Brinda Sateesh
Discussion posts and replies are publicly visible
You can build a simple logic in SaveInto of a grid to loop through each item and sum up the hours for same date, then you can put the validation message if the sum is coming more than 8 hours for the same day. Hope you can get started building the logic and you will see the result.
You will need to take into account, that a user enters multiple leave items which will form multiple groups of similar or overlapping dates.
Idea: Create a list of maps holding a date and the sum of hours for that date.
My suggestion is the following:
- user the reduce() function to iterate on all entered
- Inside reduce(), check whether the list of maps already contains an item for that date
- Either add the item's hours to the existing map, or append a new map to the list
Then you know the sum of hours for each day and can do the validation based on this.
Hi Stefan,
Thanks for your reply. Actually I did not understand how to apply the suggestion you have mentioned. Can you please explain with coding?
Hi Durgesh,
Thanks for your reply? How to achieve this?
My description already is a high-level description of the coding. Just create a separate expression that does the item logic and then use it inside reduce() to iterate on the list.
Give it a try and come back for more specific issues.
Thank you Stefan. I used my own logic and got a way to get the duplicate dates total requested hours. It works fine too.