String replace in fields for Jira Project Automation

revyx October 1, 2019

Hello, I'm trying to automate the process of filling estimated hours in my project. What I am trying to do is to get the input from a field (text), for which at the moment I'm testing out using just the description field.

The idea is to be able to manipulate the string of the field to automatically add it to the Original Estimate field. I am trying at the moment (without success) using Project Automation, New Action > Edit Issue.

 

I have 2 scenarios for which I need help:

1. Let's say I have in description the following value: 100 hours

I want to use jira automation to get this value copied from the description field over to the Original Estimate one. When trying it directly, the word "hours" isn't recognised in the field, so it needs to be replaced to "h". 

 

2. Another example is when I have something different than hours in the description and I need to do some calculations with it. 

Let's say I'm translating and the scope is 10000 words, which take 500 words an hour, so when having in description "10000 words".

I need to be able to remove the word "words", divide the number by 500 and add "h" at the end and copy it to the Original Estimate field.

 

Hence I would like to know if there's a way to manipulate text strings using Json so I can just say. Where "hours" replace it with "h". 

 

Thanks in advance!

 

1 answer

1 accepted

1 vote
Answer accepted
fran garcia gomera
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.
October 1, 2019

This JSON works fro the 100hours (without space) situation.

Changing de regex could make it work for any other cases.

{

"fields": {
"description": "{{issue.summary.jsonEncode}}",
"timetracking": {
"originalEstimate": "{{issue.description.match("(?:.*)\s(\d+)hours")}}h"
}

}
}
revyx October 1, 2019

Hello, thanks for your answer Fran. unfortunately I get an error when trying to run it. 

 

Description in the field:

image.png

In the automation rules it looks like:

image.pngError:

image.png

fran garcia gomera
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.
October 1, 2019

The regex is prepared for finding the text after some other text, change it by deleting (?:.*)\s and It will find the 'xxxhours' at beginning of the line, if you add \s* it will find 'xxx hours' with or without space between the number and the word hours.

playing with the regex you can make this work fine.

I recomend you https://regexr.com to try and to learn about regex

Like revyx likes this
revyx October 2, 2019

Thanks Fran! I was able to make it work in all cases, thanks for the help and the recommendation on regex, will definitely have a look to learn more. 

Have a nice day!

Suggest an answer

Log in or Sign up to answer