How can I use advanced branching to loop through a lookup table to update user defined text?

Ricardo Acunzo
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 18, 2024

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.pngimage.pngimage.pngimage.png

image.pngimage.pngimage.png

 

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

 

@Bill Sheboy Tagging since you had a lot of good info with many examples. This one I think is slightly different.

@denis_sheridan I think you had a similar use case so I thought I'd tag you as well

 

Any help is appreciated

thanks 

 

1 answer

1 accepted

1 vote
Answer accepted
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 18, 2024

Hi @Ricardo Acunzo -- 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, 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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events