Skip to main content
May 14, 2021
Question

how can I identify a single item using REJECT I try using fv!item but it does not work

  • May 14, 2021
  • 5 replies
  • 0 views

I been trying to use the correct way for years now, it seems there is not enough documentation online. I know you can use fn!isnull but is there other functions similar to it? All I want to do is to compare to a simple item. If array contains 3, then remove it. Is there a way to identify a single item like fv!item?

a!localVariables(
local!array:{1,2,3,4},
reject(fv!item=3, local!array)
)

wish it will return {1,2,4}

5 replies

stefanhelzle0001
May 14, 2021

What is your goal?

In general, the looping functions like reject call a function for each item in your list. Depending on function and output they do various things. Reject removes the item in case the function return true.

No you can either use built in functions or your own expressions. Important is that you pass the value using an underscore "_" into the function.

docs.appian.com/.../Expressions.html

Your case:

You create a helper expression with a single integer input. Code would be like

ri!value = 3

Now you use reject like this

reject(rule!helper(value:_), local!array)

ranjiths0003
May 18, 2021

Hi Sergio,

a!localVariables(
local!array:{1,2,3,4},
reject(exact(_,3), local!array)
)

above code will return a result as you expect (1,2,4)

mikes0011
Brainy
May 18, 2021

I'm unclear what exactly you're trying to do but it seems like you're trying to use an a!forEach() loop, but for whatever reason you've left out the a!forEach() call that would be needed.  "fv!item" is a property that's only accessible within an a!forEach() loop, which is why you're getting the error message in your screenshot.

I've found that reject() is no longer needed in basically any use case, because now you can just have a!forEach() check for your exclusion condition and return an empty set on that position in the array.  As long as there are any other non-empty results, empty sets will be ignored in the final result (and if you need to handle the case of all empties, then wrap the entire a!forEach() statement in a!flatten() to get around this).

a!localVariables(
  local!array: { 1, 2, 3, 4 },
  
  a!forEach(
    local!array,
    if(
      fv!item = 3,
      {},
      fv!item
    )
  )
  /* reject(fv!item=3, local!array) */
)

Result:

davel001150
May 20, 2021

Yeah, Mike, I find myself reflexively wrapping a!forEach in a!flatten() a lot.

mikes0011
Brainy
May 20, 2021

It's worth it to be able to completely weed out all calls of reject().