Skip to main content
Known Participant
Jan 9, 2023 10:56 AM UTC
Question

Add null to array

Hello Appian People,

Do you have any idea how to to implement this case:

So for example variable arr must be the same length value of variable value:

local!arr:{1,2,3}

local!value: {"a","b","c"}

But if incase of variable arr is not equal value size of variable value. It needs to add null value on the local!arr  , example:

local!arr:{1}

local!value: {"a","b","c"}

local arr expected ouput must be : local!arr{1,null,null}

another case example:

local!arr:{1,2}

local!value: {"a","b","c","d"}

local arr expected ouput must be : local!arr{1,2,null,null}

7 replies

stewart.burchell
Employee
Jan 9, 2023 11:02 AM UTC

It should just be the case of determine the difference in size of the arrays and adding to the smaller array an enumeration of null values to fill out the difference.

stewart.burchell
Employee
Jan 9, 2023 11:06 AM UTC

...like this:

fn!append(
    local!arr,
    fn!repeat(fn!length(local!value)-length(local!arr), null)
  )

Obviously you'd have check beforehand that local!arr was in fact smaller than local!value but otherwise this should do the trick,...

konduruc733182
Inspiring
Jan 9, 2023 11:03 AM UTC

Hello joselleo9535,

hope this is what you are asking for, this will only display a null value as output but will not add the value to the array.

a!localVariables(
  local!arr:{1},
  local!values:{1,2,3},
  {
   a!flatten(
     a!forEach(
       items: local!values,
       expression: {
         index(local!arr,fv!index,null())
       }
     )
   )
  }
)

We can wait for the experts to solve your question!

richardm900458
Inspiring
Jan 9, 2023 11:07 AM UTC

i would rather ask, if the implementation is 100% fine, if you are required to add null values into your array. Can you let us in the whole story? My feeling is, we should fix the root cause instead of the symptom

New Participant
Jan 9, 2023 1:17 PM UTC

Hi,

You can try this solution, this will add null values to the array which has a smaller number of values into it.

a!localVariables(
local!arr: { 1 },
local!value: { 1, 3, 5 },
local!diff: if(
a!isNullOrEmpty(difference(local!arr, local!value)),
difference(local!value, local!arr),
difference(local!arr, local!value)
),
if(
a!isNullOrEmpty(local!diff),
local!diff,
if(
a!isNullOrEmpty(difference(local!arr, local!value)),
append(
local!arr,
a!forEach(items: local!diff, expression: null())
),
append(
local!value,
a!forEach(items: local!diff, expression: null())
),
)
)
)

richardm900458
Inspiring
Jan 10, 2023 9:40 AM UTC

hi prachig,
please use this feature when you inserting code

New Participant
Jan 10, 2023 11:09 AM UTC

Hi Richard,

Yes definitely I'll use this feature from now. Thank you for this information.