Workflow - Issue with "Define Variable" operator?

Hello,

I implemented a worklfow sending emails with roles without identities. It works as following:

  • getting all roles
  • by loop:
  1. get identities for each role
  2. if the role has not assigned identities => send an email with role info

I would like to improve it in order to send one email with all roles without identities at once. I proceeded as following:

  1. Define a variable1 before the loop
  2. Define a second variable2 within the loop to concatenate the role id with the variable1.
    However, it doesn’t seem to be possible since I’m getting the initial variable1 value. Thus, I would like to know if it’s a limitation or if I’m not using it correctly. Thank you



What you are trying to do isn’t possible with your approach of using loops.

Once you set a variable using Define Variable, you can’t modify the variable. You can only create a new variable, which may reference the previous variable. Your loop is actually creating several new variables that will each individually contain the value roles: {role name}. However, you cannot reference these variables outside of the loop. When you reference defineVariable1.roles in your email, the value will still be roles because your loop can’t modify it.

The other problem is that loops are asynchronous. Steps that come after the loop cannot reference steps inside of the loop.

The only way I see to solve your use case in Workflows is to implement synchronous recursion, which would allow you to pass the list of roles and also pass a value that appends the name of each role upon subsequent invocations of the recursive workflow. This is a tricky concept to understand, but it should be feasible.

Here’s a blog post on synchronous recursion:

Thank you @colin_mckibben

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.