Forums

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

Jira smart value - automation for jira

Arkadiusz Baka
Contributor
September 29, 2022

Hi, I want to set external ticket number to customfield by searching it in issue's comments

I have smartvalue code like: {{#issue.comments}}{{body.match(".*Ticket number: \s*(.*)")}}{{/}}

but this give me result like :

2022-09-29_16-31-25.png

Problem is that the number is repeated three times, because it is in  three comments.

How to I get only first match in smartvalue?

i try:

{{#issue.comments}}{{body.match(".*Ticket number: \s*(.*)").get(0)}}{{/}}

but it doesn't work

2 answers

1 accepted

4 votes
Answer accepted
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.
September 29, 2022

Hi @Arkadiusz Baka 

The match() function can produce a collection (not a list) when there are multiple values found.  If you want just one match, perhaps convert to a list with split() and grab the first one.

{{issue.comments.body.match(".*Ticket number: \s*(.*)").split(",").first}}

Kind regards,
Bill

Arkadiusz Baka
Contributor
September 30, 2022

Thanks a lot for the clarification. It works great

Like Bill Sheboy likes this
2 votes
Mark Segall
Community Champion
September 29, 2022

Hi @Arkadiusz Baka - Perhaps set the trigger to comment added so that it executes against the current comment instead of searching through all issue comments.  You could do something like this:

  • TRIGGER: Issue Commented
  • CONDITION (Issue Fields Condition)
    • Your Custom Field is empty
  • ACTION: Edit Issue
    • Your custom field
    • {{comment.body.match(".*Ticket number: \s*(.*)")}}
Arkadiusz Baka
Contributor
September 30, 2022

Hi, I need to check the existing comments because I want to update the existing tickets.

Like Mark Segall likes this

Suggest an answer

Log in or Sign up to answer