Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,456,276
Community Members
 
Community Events
176
Community Groups

How to use .replace correctly, keep getting json error

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 Dec 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?

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 Dec 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

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 Dec 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.

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?

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

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
TAGS

Atlassian Community Events