To extract data from a data subset where two values are same

Certified Associate Developer

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

Parents
  • 0
    Certified Lead Developer

    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.

  • 0
    Certified Associate Developer
    in reply to Stefan Helzle

    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?

Reply Children