Date Range validation

Hi ,

I have a list of dictionaries with date ranges(refer below screenshot)

i need validation that if i give a date and if the given date is overlapped with any of the dates(start and end date) i should get a validation. 

for example;

start date : 05/10/2023

end date : 05/15/2023

i'm comapring the given date in this date range for each dictionary for that it is working fine but if i select date between 05/09/2023 and 05/16/2023 i should get validation that is not working,and there are many dictionaries like this.  Cany anyone help me how to do this?

  Discussion posts and replies are publicly visible

Parents Reply Children
  • 0
    Certified Lead Developer
    in reply to Stefan Helzle

    Operators in Appian can easily compare a value against a list of values. Depending on your exact requirement, this should be pretty simple.

    a!localVariables(
      local!ranges: {
        a!map(start: date(2023, 1, 1), end: date(2023, 2, 1)),
        a!map(start: date(2023, 2, 1), end: date(2023, 3, 1)),
      },
      local!date: date(2023, 1, 15),
      {
        local!date >= local!ranges.start,
        local!date <= local!ranges.end
      }
    )

  • Hi Stefan,

    In simple terms employee is applying for leave and if user want to apply for new leave or edit applied leave there should not be overlapping between existing leaves applied.

    I just have UI with start date and end date, once user submits the form data is stored in database. while changing the dates in  the ui again there should not be overlap.

  • 0
    Certified Lead Developer
    in reply to Druva

    This is a code snippet that checks one range against other ranges and returns true if there is an overlap.

    a!localVariables(
      local!ranges: {
        a!map(start: date(2023, 1, 10), end: date(2023, 1, 20)),
        a!map(start: date(2023, 2, 12), end: date(2023, 3, 1)),
      },
      local!new: a!map(start: date(2023, 1, 15), end: date(2023, 2, 1)),
      a!forEach(
        items: local!ranges,
        expression: and(
          local!new.start <= fv!item.end,
          local!new.end >= fv!item.start
        )
      )
    )