Skip to main content

8 replies

harshitb6843
January 11, 2022

Hi there,

This really depends on the size of the data and the type of filters you want to apply to the data.
If the size is small, then you can iterate through the data and set 'null' where the filter turns out to be false. 
And then at the end, reject all the null values. 

However, I am interested in knowing more about the use case here, 

January 11, 2022

Sure,

Actually in the editable grid i want to  apply the filters .. where the data subset in the grid fetch data from stored proc ... ..i cant change the stored proc because of dependents .... so wanted to know the approach to filter the data which was getting fetched from stored proc

harshitb6843
January 11, 2022

Oh. 

Changing the SP should not create any problem for the dependents as those new filters inputs, that you will be adding,  will only be applied when they are passed. For the rest of the cases, the SP should return a similar type of data. 

And anyways, Appian will never recommend filtering the data on the front end, instead of doing it on the backend as it can have a performance impact on the interface/rule and may result in poor UX. 

Let's see what other members have to say about it. 

peter.lewis
Participating Frequently
January 11, 2022

Like the other poster said, in general I recommend doing your filtering during your query because the database is much more efficient at filtering than running an expression. That being said, there are some cases where it's necessary to filter in an expression, so if you have a relatively small dataset then there are two methods I've typically used to filter on the fly:

a!localVariables(
  local!cases: {
    a!map(
      id: 1,
      priority: "Low",
      status: "New",
      dateUpdated: today()
    ),
    a!map(
      id: 2,
      priority: "Medium",
      status: "Pending Response",
      dateUpdated: today() - 4
    ),
    a!map(
      id: 3,
      priority: "Low",
      status: "Closed",
      dateUpdated: today() - 2
    ),
    a!map(
      id: 4,
      priority: "High",
      status: "New",
      dateUpdated: today() - 1
    ),
    
  },
  
  /* Option 1*/
  a!forEach(
    items: local!cases,
    expression: if(
      fv!item.priority = "Low",
      fv!item,
      {}
    )
  ),
  
  /* Option 2 */
  index(
    local!cases,
    wherecontains(
      "Low",
      local!cases.priority
    ),
    {}
  )
)

Option 1 uses a!forEach() to do a comparison, so any logical statement can be used to "filter" the data. It works because a!forEach() implicitly flattens all lists, so if you provide an empty list as the response in the false case, those items are filtered out.

Option 2 uses a combination of index() and wherecontains() that is most useful if you're specifically looking if a value exists. The where contains tells you which indexes contain that value, and then you return the corresponding indexes from your original dataset with the index() function.

January 11, 2022

Thanks Peter