Clean up NULL values and copy good values on another Array CDT - a!forach loop with append() & inssert()

Hi Community,

I am struggling with a simple expression rule.

I tried with append, insert and other functions, but i didn't manager. I expect those functions to return the previous array + the new addition.

I would like to generate a second array without "null" values of my CDT type, so I have an array only with proper data.

For that I did below expression rule:

 

load(
  local!itemsWithNull:{{null, null, 'type!{urn:com:appian:types}MyData'('uId': 5, 'name': "changed", 'symbol': "changed", 'market': "aa", 'isActive': false), null, null, null, null, 'type!{urn:com:appian:types}MyData'('name': "new", 'symbol': "new")}},
  local!itemsClean:{'type!{urn:com:appian:types}MyData'()},

  
  {a!forEach(
    items: (local!itemsWithNull),
    expression: {
      if(
        isnull(fv!item),
         fv!index & " is null",
         {
           "ADDED" & append(local!itemsClean,fv!item) & "END ADDED",
         }

        ) 
    }
      
  ),
  reverse(local!itemsClean),
  }

)

 

On my first iteration, I expect to get something like this (currently the expression rule is kind of in my debug mode :) )

 

FIRST ITERATION

 

"ADDED[uId=5, name=changed, symbol=changed, market=aa, isActive=false]END ADDED"

However, I have something like this:

 

"ADDED[uId=, name=, symbol=, market=, isActive=]; [uId=5, name=changed, symbol=changed, market=aa, isActive=false]END ADDED

 

 

SECOND ITERATION:

On my second iteration of valid data, I would expect to have a result like:

"[uId=5, name=changed, symbol=changed, market=aa, isActive=false]; [uId=, name=new, symbol=new, market=, isActive=]END ADDED"

However, I get something like this:

(the new data is present, but i lost my previous one)

"ADDED[uId=, name=, symbol=, market=, isActive=]; [uId=, name=new, symbol=new, market=, isActive=]END ADDED"

 

This is how my output looks like: 

 


List of Variant: 9 items
    List of Text String: 1 item
        "1 is null"
    List of Text String: 1 item
        "2 is null"
    List of Text String: 1 item
        "ADDED[uId=, name=, symbol=, market=, isActive=]; [uId=5, name=changed, symbol=changed, market=aa, isActive=false]END ADDED"
    List of Text String: 1 item
        "4 is null"
    List of Text String: 1 item
        "5 is null"
    List of Text String: 1 item
        "6 is null"
    List of Text String: 1 item
        "7 is null"
    List of Text String: 1 item
        "ADDED[uId=, name=, symbol=, market=, isActive=]; [uId=, name=new, symbol=new, market=, isActive=]END ADDED"
    MyData
        uId: null (Number (Integer))
        name: null (Text)
        symbol: null (Text)
        market: null (Text)
        isActive: null (Boolean)

 

Thanks very much in advance for any recommendation! 

 

Best regards,

Manuel

 

 

 

 

  Discussion posts and replies are publicly visible