Workflow - Issue with "Define Variable" operator?

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: