Skip to main content
sanjuktab2257
May 2, 2025
Question

Is 2 operations within the same expression in a for each loop possible?

  • May 2, 2025
  • 7 replies
  • 0 views

Can we perform 2 operations within the same expression of a forEach loop possible? (Ex: zip in python.)

7 replies

stefanhelzle0001
May 2, 2025

Not sure what you are looking for. Do you want to describe the problem you want to solve?

May 2, 2025

You can perform many operations within the same expression of a forEach loop.  Anything in particular you're having difficulty doing?

yashwantha0914
May 2, 2025

Hi [mention:9ce4b939559d45dc807b9271b84c0a9b:e9ed411860ed4f2ba0265705b8793d05] 

"zip in python", so based on this i read about zip function in python

So, we have a similar function in Appian: merge()

A
nd can you please explain your usecase.

sanjuktab2257
May 5, 2025

Thank you [mention:f0523105fd4d4e879f169a28f3dd0ec5:e9ed411860ed4f2ba0265705b8793d05] , that was helpful.

It seems like "merge" is only for lists. Do you know how to merge two dictionaries.

a!localVariables(
  local!var1: {"John": "A", "Sam": "B", "Rose": "C"},
  local!var2: {"Smith": 1, "Williams": 2, "Thompson": 3},
  a!forEach(items: merge(local!var1.value, local!var2.value),
  expression: concat(fv!item[1], " ,", fv!item[2])
)

the expected output should be: "A ,1", "B, 2", "C, 3"

May 6, 2025

hi [mention:9ce4b939559d45dc807b9271b84c0a9b:e9ed411860ed4f2ba0265705b8793d05] , see if this helps.

a!localVariables(
local!var1: { "John": "A", "Sam": "B", "Rose": "C" },
local!var2: { "Smith": 1, "Williams": 2, "Thompson": 3 },
local!var1Values: a!flatten(
a!forEach(
items: a!keys(local!var1),
expression: if(
fv!isLast,
stripwith(keyval(local!var1, fv!item, ":", ","), "]"),
keyval(local!var1, fv!item, ":", ",")
)
)
),
local!var2Values: a!flatten(
a!forEach(
items: a!keys(local!var2),
expression: if(
fv!isLast,
stripwith(keyval(local!var2, fv!item, ":", ","), "]"),
keyval(local!var2, fv!item, ":", ",")
)
)
),
merge(local!var1Values, local!var2Values)
)