Extract date using index

I am trying to extract out an array from allResults which contains a certain ID . since ID is an integer , i used index and where contains 

 

index( local!allResults, wherecontains( ri!Id, tointeger(touniformstring( local!allResults.Id)) ) )

 

 

What if i have to extract an array which is greater than a  certain date  from allResults ?

 

If i want equals to i could have tried  

 

index( local!allResults, wherecontains( ri!date,  local!allResults.date)) ) )

 

 But i want to extract out an subset array from a master array , where the date in master array is greater than today 

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer
    Hi, instead of using wherecontains it sounds like you want to build something to the effect of "whereGreaterThan". You could do so inline by using a!forEach. Iterate over the list local!allResults.date, and for each item compare the value to ri!date. If the value is greater, return the index, otherwise, return {}. That way, you'll be passing an array of the indices you're after to fn!index, and it will return the subset array that you're looking for, because index's second (named index) parameter accepts arrays (index (Number (Integer)): The index or array of indices of the array.).

    If you're on an earlier version of Appian and a!forEach isn't available, you can accomplish the same thing by creating a new rule and using apply().

    Thanks,
    Dan
  • +1
    Certified Lead Developer
    Hi,

    Please use index(masterArray, where(apply(rule!isDateGreater(data:_)),{masterArray}),{}).

    rule!isDateGreater
    -----------------------------
    add your date condition, result should be boolean.

    Hope it will help you..!!!
  • +1
    Certified Lead Developer

    Per daniell's suggestion, but perhaps even easier, I would use a!forEach like this:

     

    a!forEach(
      local!allResults,
      if(
        fv!item.date > today(),
        fv!item,
        {}
      )
    )

    This would allow you to return an array of the matching results directly, without having to go through the runaround of calculating a list of indexes to then use for the index() function on the array.