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:
The following screenshots are a simplified version of what I'm attempting to do (my text field and lookup table would be much larger)
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.