# Workflow - Issue with "Define Variable" operator?

**URL:** <https://developer.sailpoint.com/discuss/t/workflow-issue-with-define-variable-operator/21628>\
**Category:** SHF Discussion and Questions\
**Tags:** workflows, sailpoint-identity-security\
**Created:** [November 28, 2023, 9:38am UTC](https://developer.sailpoint.com/discuss/t/workflow-issue-with-define-variable-operator/21628 "2023-11-28T09:38:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fatimahm](https://avatars.discourse-cdn.com/v4/letter/f/3d9bf3/32.png) [@fatimahm](https://developer.sailpoint.com/discuss/u/fatimahm)\
**Post date:** [November 28, 2023, 9:38am UTC](https://developer.sailpoint.com/discuss/t/workflow-issue-with-define-variable-operator/21628/1 "2023-11-28T09:38:16Z")

</div>

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

 ![image](https://global.discourse-cdn.com/sailpoint/original/2X/5/544c60d8990ceb4a707915cbffd1f043e62b6c27.png)  
 ![image](https://global.discourse-cdn.com/sailpoint/original/2X/e/ef7667ef8a7dae1f69b03b5dce788381b22054b4.png)  
 ![image](https://global.discourse-cdn.com/sailpoint/original/2X/a/a3fb59b48c025151a0ec37e14cceaa5f225f8226.png)

---

<div class="post-metadata">

**Author:** ![colin\_mckibben](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/colin_mckibben/32/37182_2.png) [@colin\_mckibben](https://developer.sailpoint.com/discuss/u/colin_mckibben)\
**Post date:** [December 14, 2023, 8:12pm UTC](https://developer.sailpoint.com/discuss/t/workflow-issue-with-define-variable-operator/21628/2 "2023-12-14T20:12:35Z")

</div>

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:

> [@Recursive Workflows in IdentityNow](https://developer.sailpoint.com/discuss/t/recursive-workflows-in-identitynow/16235):
>
> IdentityNow Workflows provides a [loop operator](https://documentation.sailpoint.com/saas/help/workflows/workflow-operators.html#loop) that allows a workflow to process many items in a list of data in a quick and efficient manner. While the loop operator is a built-in component of Workflows, there is another way to achieve looping functionality using features that are currently supported in the product. In this blog, I will demonstrate how to implement recursion in Workflows to achieve looping behavior without the need for the loop operator. What is recursion? …

---

<div class="post-metadata">

**Author:** ![fatimahm](https://avatars.discourse-cdn.com/v4/letter/f/3d9bf3/32.png) [@fatimahm](https://developer.sailpoint.com/discuss/u/fatimahm)\
**Post date:** [December 29, 2023, 10:11pm UTC](https://developer.sailpoint.com/discuss/t/workflow-issue-with-define-variable-operator/21628/3 "2023-12-29T22:11:36Z")

</div>

Thank you @colin_mckibben

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/sailpoint/original/2X/f/f2136700ed5e3703e0b85e02f6be799dacca7735.png) [@system](https://developer.sailpoint.com/discuss/u/system)\
**Post date:** [February 27, 2024, 10:12pm UTC](https://developer.sailpoint.com/discuss/t/workflow-issue-with-define-variable-operator/21628/4 "2024-02-27T22:12:08Z")

</div>

Closed on February 27, 2024, 10:12pm UTC

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