Forums

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

Fill a custom field with variable taken from title

Patrik Klein January 31, 2024

Hi,

i'm in desperate need of help. I'd like to fill a custom field with a number from my issue title.

I'm sending mails to Jira, with a fixed subject "blablabla bla bla 1245", i want every created issue in jira to check if the title field starts with "blablabla" and if it does it should put the what ever number is in the title into a custom field. 

I can get to the part where i need to fill in the custom field but i dont know how to parse for the 1245 or what ever number is at the end. The number i need is allways at the end and without spaces

any ideas?

1 answer

1 accepted

3 votes
Answer accepted
Pierre Ibrahim
Contributor
January 31, 2024

Hi @Patrik Klein

I think a plugin like JWT can potentially get you there depending on your use case.

Screenshot 2024-01-31 111748.png

from your example above, this function replaces a specific regex with nothing, so taking out all characters and spaces will leave you with the number which you can then assign to whatever field you like.

And with JWT you can do a condition on the function to only run when a specific thing occurs, in your example, if the summary has "blablabla"

Pierre Ibrahim
Contributor
January 31, 2024

You can also potentially use JIRA Automation if you do not have JWT or do not wish to install a new plugin. This answer has an example of using regex in automation: https://community.atlassian.com/t5/Jira-Software-questions/String-replace-in-fields-for-Jira-Project-Automation/qaq-p/1191599

Patrik Klein February 1, 2024

Hey thanks for the answer, im pretty sure that i am on the corret path thanks to your example still having issues getting the the parsing to work though

i tried to figure it out with the other post and 'm using something like this rn:

{

 

  "fields": {

     "description": "{{issue.summary.jsonEncode}}",

     "customfield_10050": {

        "Niederlassungsnummer": "{{issue.description.match("(?:.*)\s(\d+)")}}"

     }

 

  }

}

but i get an error message functionvalue has to be a string

Pierre Ibrahim
Contributor
February 1, 2024

I have a different solution for you that I was able to try successfully in my test environment

Screenshot 2024-02-01 081901.png

The regex reads: {{issue.summary.match("(\d+)(?!.*\d)")}}

basically only get the last digits in a string where there are no non digit characters, so it wouldn't get digits in the middle of the string, just at the end.

This worked great in my test environment, have it on issue create for the value changing and you'll be good to go!

Credit to: https://stackoverflow.com/questions/5320525/regular-expression-to-match-last-number-in-a-string

Hope that helps!

 

Patrik Klein February 1, 2024

Thank you so much, this works perfectly for me!

Pierre Ibrahim
Contributor
February 1, 2024

Excellent! Glad I was able to help!

Like Patrik Klein likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events