How to use .replace correctly, keep getting json error

Steven Johnson December 13, 2022

I have a Jira Automation question. I have created a rule in UAT and tested and it works fine, but when I duplicated it in production, I keep getting a json error.

I am using a rule to create a new story in another project, when the originating story is marked "done". I am trying to replace words in the title (summary) with alternate words using the following json code in the "additional fields" section of "create issue" action:

{"fields": {"summary": "{{issue.summary.replace("Prep Table","Pre-Prep Table").replace("Monitored Population","Pre-Prep Table")}}"}}
Essentially if the title has "Prep Table" within it, I want that changed to "Pre-Prep Table".
This syntax works in other areas with different words, but it errors on this one. Is there a way to do this or any clue why this causes an error? "Error while parsing additional fields. Not valid JSON" (the error message)
Thank you!
SteveJSON Error.jpg

1 answer

1 accepted

0 votes
Answer accepted
Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 13, 2022

Hello @Steven Johnson 

The syntax works for me when I use it in a rule.

{
"fields": {
"summary": "{{issue.summary.replace("Prep Table","Pre-Prep Table")}}"
}
}

Do you have any other Advanced Edit functions in your rule? Perhaps the error message is referring to a different one. Can you show us the audit log and a full list of the components of the rule?

Steven Johnson December 13, 2022

Other than being extremely lengthy, it's pretty straightforward. The error points to that exact JSON, but maybe I'm missing something. Here is the audit log with the error and the long components list.JSON Error Audit Log.jpgJSON Error (all components).jpg

Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 13, 2022

If I am reading the audit log correctly, it seems that the problem is arising in the fourth IF block (noting that the third IF block is not an actual block that includes actions). Is that correct from your perspective?

And the JSON you are using is being used in a Create Issue action, correct?

And you are trying to set the Summary of the newly created issue to match the Summary of the triggering issue, but with text replaced. Correct?

If the above is correct, then you can simply set the Summary field using a smart value directly, without using Advanced Edit

{{triggerIssue.summary.replace("Prep Table","Pre-Prep Table")}}

Screen Shot 2022-12-13 at 1.41.01 PM.png

Like # people like this
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.
December 13, 2022

Hi @Trudy Claspill 

When you tested that expression initially, was that with Jira Cloud?

If so...I wonder if Jira Server/Data Center is having a problem with the nested double-quotation marks in the JSON to set the summary.

Regardless...setting the expression to the field directly as you described, without the advanced edit, seems a good work-around.

Thanks,
Bill

Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 13, 2022

Ah, yes, I did test on Jira Cloud.

In which case single quotes should be tried for surrounding the text values that will get replaced.

Steven Johnson December 14, 2022

It's always the simplest of solutions that I can never come up with. Thanks, that works for now (in UAT), so I'm hoping it works correctly in Production. The advanced edit before also worked in UAT but not Prod, so if this doesn't work then there's a discrepancy between our UAT and Prod.

I thought I was on server, not Cloud, but the double quotes worked exactly as written above, so I wonder why that is, if it's not supposed to?

Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 14, 2022

We didn't mean to say that the double quotes would not work on Server, just that it was possible that they would not work because of the use of double quotes elsewhere in the JSON. I didn't test on a Server instance, so I could not say with certainty that the double quotes would or would not work there.

For the Advanced Edit working in UAT but not prod, were you running the exact same rule in UAT? 

Lastly, if you find that the suggestion does work in prod, please consider marking the Answer as Accepted to help other users find the posts that include working solutions.

Like Bill Sheboy likes this
Steven Johnson December 14, 2022

Thanks @Trudy Claspill 

And yes, the rule was exact, double checked that, and had someone else look it over and run tests. I've had some other strange issues in the past when using the "additional fields", so I guess it's some unseen technical issue that I just am not seeing.

Your suggestion worked and was even easier to understand for future maintenance, so thank you!

 

Steve

Suggest an answer

Log in or Sign up to answer