Inconsistent data types (Text vs Variant) in List of Map output

I am working with a rule in Appian where I expect a consistent structure of List of Map, but I am seeing inconsistent data types in the output.

a!localVariables(
local!indexval: index(
ri!userFilters,
"userFilter",
null
),
local!filters: split(local!indexval, ";"),
a!forEach(
items: local!filters,
expression: a!localVariables(
local!valueStart: find("value=[", fv!item),
local!valueBlock: if(
isnull(local!valueStart),
"",
mid(
fv!item,
local!valueStart + 7,
len(fv!item)
)
),
local!cleanValueBlock: substitute(local!valueBlock, "]", ""),
/*Values */
local!AccountName: if(
find("name=AccountName", fv!item) > 0,
a!forEach(
items: split(local!cleanValueBlock, ","),
expression: trim(substitute(fv!item, """", ""))
),
{}
),
local!ProductCategory: if(
find("name=Product Category", fv!item) > 0,
a!forEach(
items: split(local!cleanValueBlock, ","),
expression: trim(substitute(fv!item, """", ""))
),
{}
),
a!map(
AccountName: local!AccountName,
ProductCategory: local!ProductCategory
)
)
)
)



expecting ProductCategory and Account name in single map

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer
    {}

    The {} come up as List of variant. To avoid having list of variants in the output cast these {} to string using tostring({}). That will give expected output. 

  • After converting it into string Getting output


    expected :

  • 0
    Certified Lead Developer

    Try this: 

    a!localVariables(
    local!indexval: index(ri!userFilters, "userFilter", null),
    local!filters: split(local!indexval, ";"),

    /* Find the segment containing AccountName */
    local!accountSegment: a!forEach(
    items: local!filters,
    expression: if(find("name=AccountName", fv!item) > 0, fv!item, null)
    ),
    local!accountRaw: index(
    filter(not(isnull(fv!item)), local!accountSegment),
    1, null
    ),

    /* Find the segment containing Product Category */
    local!productSegment: a!forEach(
    items: local!filters,
    expression: if(find("name=Product Category", fv!item) > 0, fv!item, null)
    ),
    local!productRaw: index(
    filter(not(isnull(fv!item)), local!productSegment),
    1, null
    ),

    /* Parse AccountName values */
    local!accountValues: if(
    isnull(local!accountRaw),
    {},
    a!localVariables(
    local!start: find("value=[", local!accountRaw),
    local!block: mid(
    local!accountRaw,
    local!start + 7,
    len(local!accountRaw)
    ),
    local!clean: substitute(
    substitute(local!block, "]", ""),
    "isArray=true,", ""
    ),
    filter(
    not(isnull(fv!item)) && fv!item <> "",
    a!forEach(
    items: split(local!clean, ","),
    expression: trim(substitute(fv!item, """", ""))
    )
    )
    )
    ),

    /* Parse ProductCategory values */
    local!productValues: if(
    isnull(local!productRaw),
    {},
    a!localVariables(
    local!start: find("value=[", local!productRaw),
    local!block: mid(
    local!productRaw,
    local!start + 7,
    len(local!productRaw)
    ),
    local!clean: substitute(
    substitute(local!block, "]", ""),
    "isArray=true,", ""
    ),
    filter(
    not(isnull(fv!item)) && fv!item <> "",
    a!forEach(
    items: split(local!clean, ","),
    expression: trim(substitute(fv!item, """", ""))
    )
    )
    )
    ),

    /* Single combined map */
    a!map(
    AccountName: local!accountValues,
    ProductCategory: local!productValues
    )
    )

    Issue
    Two separate maps
    isArray=true
    Empty strings in output

  • 0
    Certified Lead Developer

    Your if() returns empty List of Variant when the condition fails, and a!forEach makes one map per filter (not merged).
    Type the empty fallback and merge after the loop.

    See below - Returns one map with both keys as List of Text.

    a!localVariables(
      local!filters: split(index(ri!userFilters, "userFilter", null), ";"),
      local!parsed: a!forEach(
        items: local!filters,
        expression: a!localVariables(
          local!vStart: find("value=[", fv!item),
          local!vBlock: if(isnull(local!vStart), "", mid(fv!item, local!vStart + 7, len(fv!item))),
          local!values: a!forEach(
            items: split(substitute(local!vBlock, "]", ""), ","),
            expression: trim(substitute(fv!item, """", ""))
          ),
          a!map(
            type: if(find("name=AccountName", fv!item) > 0, "A", "P"),
            values: local!values
          )
        )
      ),
      a!map(
        AccountName: index(local!parsed, wherecontains("A", local!parsed.type), a!map()).values,
        ProductCategory: index(local!parsed, wherecontains("P", local!parsed.type), a!map()).values
      )
    )