Skip to main content
March 27, 2025
Question

how to create nested list

  • March 27, 2025
  • 5 replies
  • 0 views

hi,

i am using a!forEach to create a list of variants and wanted to return the iteration item as Array/List itself

for eg,

a!localVariables(
local!testVariable: { "A", "B", "C;D" },
local!valuesAsArray: a!forEach(
items: local!testVariable,
expression: if(
length(split(fv!item, ";")) > 1,
split(fv!item, ";"),
fv!item
),

),
local!valuesAsArray
)

Above expression is returning results as {"A", "B", "C", "D"}

Instead i wanted the results as {"A", "B", {"C", "D"}}.

Any suggestions on how to achieve this

    5 replies

    stefanhelzle0001
    March 27, 2025

    Appian automatically flattens such lists. I do not know of a reliable way to get the result you are looking for.

    mikes0011
    Brainy
    March 27, 2025

    If we're allowed a little leeway on what the format of the resulting data can be, it's pretty easy to handle this using a list of maps:

    March 28, 2025

    Hi [mention:19b64a2d7fab4753b0518d03557d7780:e9ed411860ed4f2ba0265705b8793d05] ,

    a!localVariables(
      local!testVariable: { "A", "B", "C;D" },
      local!valuesAsArray: a!forEach(
        items: local!testVariable,
        expression: {split(fv!item,";")}
      ),
      local!valuesAsArray
    )

    Let me know if this works!!

    varuntejg243705
    March 28, 2025

    Hi [mention:19b64a2d7fab4753b0518d03557d7780:e9ed411860ed4f2ba0265705b8793d05] ,
    You can't get the exact expected result as Appian will Flatten the list as we cannot seperately add few nested lists at the end.
    And this is the expected behaviour in Appian arrays.

    The Output Expression you get at most probable from [mention:b45a4f6a20b14a008e4e0ec732a8bf98:e9ed411860ed4f2ba0265705b8793d05]  & [mention:1c6f36915a6c4d3a8444dd997b2ebc07:e9ed411860ed4f2ba0265705b8793d05]  expressions is 
    {{"A"}, {"B"}, {"C", "D"}}

    gayatria0439
    March 28, 2025

    Hi [mention:19b64a2d7fab4753b0518d03557d7780:e9ed411860ed4f2ba0265705b8793d05] , Try using the code below.