How can I use advanced branching to loop through a lookup table to update user defined text?
Asked by Ricardo Acunzo:

I'm trying to build an automation to will replace text within a user defined text field (could be in Jira or Confluence) by looping through a lookup table (with key value pairs) with an advanced branch.

I have not been able to figure it out yet through I did try some variations per the explanations below:

<https://community.atlassian.com/t5/Automation-articles/New-Automation-action-Create-lookup-table/ba-p/2311333/page/2>

<https://community.atlassian.com/t5/Automation-articles/Update-Create-lookup-table-action-improvements/ba-p/2427798?anon_like=2451783>

The following screenshots are a simplified version of what I'm attempting to do (my text field and lookup table would be much larger)

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/330483iB0443AA5FB7150B4/image-size/large?v=v2&px=999 "image.png")![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/330484i1FCACCDD5085FEF6/image-size/large?v=v2&px=999 "image.png")![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/330485i104506B5C31CC5B4/image-size/large?v=v2&px=999 "image.png")![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/330486i0FEBD75B8FBDD9BA/image-size/large?v=v2&px=999 "image.png")

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/330489iFCA4824E958DE338/image-size/large?v=v2&px=999 "image.png")![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/330490iC9A6BE237FC41241/image-size/large?v=v2&px=999 "image.png")![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/330491iB6D178D4777EC6A1/image-size/large?v=v2&px=999 "image.png")

The desired outcome in the above would be that 123 and 456 are replaced with abc and xyz .

[@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) Tagging since you had a lot of good info with many examples. This one I think is slightly different.

[@denis.sheridan](/t5/user/viewprofilepage/user-id/5148233) I think you had a similar use case so I thought I'd tag you as well

Any help is appreciated

thanks


Answers:
author: Bill Sheboy
body: Hi [@Ricardo Acunzo](/t5/user/viewprofilepage/user-id/5523654) -- Welcome to the Atlassian Community!

Short answer: at this time, *for a small number of replacement items* I recommend solving a multiple find / replace scenario using a chain of replace() calls or replaceAll if regular expressions are needed.

For example: {{parg.replace("123","abc").replace("456","xyz")}}

When more items (or more complex replacement) is needed, do that outside of Jira, such as with an external custom service or export / import functions.

Some more information...

What you are trying to do with the advanced branch to "update" the variable cannot work that way.

Branches which *could be on more than one thing / issue* (e.g., advanced branch) are executed in parallel and asynchronously, and so each pass through the loop is independent. There is no guarantee of when such branches will finish up until the last step in the rule, and so it is likely the branch is still running when the steps after the branch process. Thus your re-created variable just repeatedly goes out of scope and vanishes. ( There is an open suggestion to add an option for sequential versus parallel processing of branches / rules: <https://jira.atlassian.com/browse/AUTO-32> )

There are elaborate workarounds to perform sequential processing for rules using webhooks to repeatedly callback themselves. These have limitations and risks, and may not be a good fit for multiple find / replacement of text.

Some other things I noticed in your rule...

I recommend avoiding using variable names which could be confused (by a person or rule) with an existing thing, such as *lookup* . I normally do this by adding a prefix, such a *var* for variables and *tbl* for tables. And so your *lookup* one could be renamed *varLookup*.

If you review that [updated article on Lookup Tables](https://community.atlassian.com/t5/Automation-articles/Update-Create-lookup-table-action-improvements/ba-p/2427798), you will find the entries function / attribute, which returns the table as a list of rows. For your advanced branch, that smart value expression would be:

```
{{xRef.entries}}
```

Although due to the reasons noted earlier, that would not help solve the update scenario.

Kind regards,  
Bill


Tags: jira