Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Add string literals as a parameter to replaceAll

John Colosi
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!
April 7, 2023

I want to do this:

  • issue.description.replaceAll("||" + myParam + "|.*", "aReplacementString")

This would replace a certain table row in the description. The row that begins with myParam in the first cell. A table row looks like this:

  • ||Column1|Field A|FieldB|FieldC

 

But the problem is that you can't add strings together as a parameter (using the plus sign). You can append a string onto an existing value (using concat), but you can't prepend.

I considered using reverse/concat/reverse/concat, which looks ridiculous. Ultimately I did this:

  • issue.summary.left(0).concat("\|\|").concat(myParam).concat("\|.*")

This is probably equally ridiculous. I'm using the first 0 characters of the summary (a field I know exists) to create a temporary variable I can use to create my regex. I'm using the server version of Jira so I can't create a variable. I'm not sure what the right way to do this is. Any help appreciated.

1 answer

2 votes
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.
April 7, 2023

Hi @John Colosi 

First, I want to note that is a clever work-around for no Create Variable action in the Server/Data Center version of automation rules.

Other approaches would be to store your search expression for the replaceAll() call in an entity property (or custom field), re-fetch, and then use that directly.  That would be slower but it might allow other regular expression content, possibly excluded by the smart value text function handling.

Kind regards,
Bill

Suggest an answer

Log in or Sign up to answer