how to remove all nulls in array and get the corresponding index of the null value

Hello Appian people,

local!arr:{1,2,null,3,null}

loca!val:{1,2,3,4,5}

I have a function that gets null indexes in an array local!arr then used that indexes to remove the value from the local!val array.

and also remove the value found in the local!arr.

 /*Get null indices */
local!getNullIndices: a!forEach(
items: local!arr,
expression: if(isnull(fv!item), fv!index, null())
),
local!removeNullIndices: remove(
local!getNullIndices,
where(
a!forEach(
items: local!getNullIndices,
expression: if(a!isNullOrEmpty(fv!item), true, false)
)
)
),

/* Removed found null in data item array */
local!data: remove(
local!arr,
where(
a!forEach(
items: local!arr,
expression: if(a!isNullOrEmpty(fv!item), true, false)
)
)
),

local!updatedVal:remove(

loca!val,

removeNullIndices

)

expected value for updatedVal is: {1,2,4}

Do you have any ideas to optimize this implementation? Thank you

  Discussion posts and replies are publicly visible

Parents
  • Hi,

    Please try this. I made a small change in your code.

    a!localVariables(
    local!arr: { 1, 2, null, 3, null },
    local!val: { 1, 2, 3, 4, 5 },
    /*Get null indices */
    local!getNullIndices: a!forEach(
    items: local!arr,
    expression: if(isnull(fv!item), fv!index, null())
    ),
    local!removeNullIndices: remove(
    local!getNullIndices,
    where(
    a!forEach(
    items: local!getNullIndices,
    expression: if(a!isNullOrEmpty(fv!item), true, false)
    )
    )
    ),

    /* Required Output */
    local!data: remove(
    local!val,
    local!removeNullIndices
    ),
    local!data
    )

Reply
  • Hi,

    Please try this. I made a small change in your code.

    a!localVariables(
    local!arr: { 1, 2, null, 3, null },
    local!val: { 1, 2, 3, 4, 5 },
    /*Get null indices */
    local!getNullIndices: a!forEach(
    items: local!arr,
    expression: if(isnull(fv!item), fv!index, null())
    ),
    local!removeNullIndices: remove(
    local!getNullIndices,
    where(
    a!forEach(
    items: local!getNullIndices,
    expression: if(a!isNullOrEmpty(fv!item), true, false)
    )
    )
    ),

    /* Required Output */
    local!data: remove(
    local!val,
    local!removeNullIndices
    ),
    local!data
    )

Children
No Data