Skip to main content
Known Participant
May 22, 2025 8:46 AM UTC
Question

Map index delete

Hello All,

I am facing issue with the following map. I am building dynamic filters. Here is the map is the output. But I wanted to delete logicalExpression:{} from the map. It can be there at any level. If logicalExpression is null then my resulted map should not contain logicalExpression:{}

a!localVariables(
  local!conditions: {
    a!map(
      operator: "AND",
      logicalExpressions: {
        a!map(
          operator: "AND",
          filters: {
            a!map(field: null, operator: null, value: null),
            a!map(field: null, operator: null, value: null)
          },
          logicalExpressions: {
            a!map(
              operator: "AND",
              filters: {
                a!map(field: null, operator: null, value: null),
                a!map(field: null, operator: null, value: null)
              },
              logicalExpressions: {}
            ),
            a!map(
              operator: "AND",
              filters: {
                a!map(field: null, operator: null, value: null),
                a!map(field: null, operator: null, value: null)
              },
              logicalExpressions: {}
            )
          }
        )
      }
    )
  },
local!conditions
)

7 replies

amaans4178
Brainy
May 22, 2025 9:28 AM UTC

As far as I understand, this may require a recursive approach, given that the structure is hierarchical and can have multiple levels.
Please feel free to correct me if I’m mistaken.

rupaa0642Author
Known Participant
May 22, 2025 10:04 AM UTC

Yes you are correct

davidj137213
Brainy
May 22, 2025 10:22 AM UTC

You ned to use a recursive approach... or try converting the array to json... replace the elements with a regular expression, and convert it again to an appian structure..

rupaa0642Author
Known Participant
May 22, 2025 10:54 AM UTC

Can you pls give me an example for JSON approach

davidj137213
Brainy
May 22, 2025 11:39 AM UTC

it would be something like....

a!fromjson(substitute(a!tosjon(local!conditions), "logicalExpressions"":[]", null))

But you have to be care of closing tags, and keep the json structure

mikes0011
Brainy
May 22, 2025 5:26 PM UTC

It's a little ambiguous what you're after, without some examples of different inputs and what you would expect the outputs to be (and why). 

Generally, you can't exactly "delete" something from a map, but similarly to the JSON approach, you could always structure an expression to build a new map from an existing map and just omit certain properties when needed.

The Expression Guru