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,556,454
Community Members
 
Community Events
184
Community Groups

Using variables in functions in smart values in JIRA for automation purpose

Hello,

I'm looking to use jira automation rules in an advanced way using variables in smart value functions.

I saw that a ticket covered this topic some time ago but even though it is marked as resolved I am having trouble applying the syntax.
Here is the ticket : https://codebarrel.atlassian.net/browse/AUT-168

I want to do the same, e.g. :
{{issue.summary.replace("blah", "{{issue.fields.reporter.displayName}}")}}


Is there a way to use variables in smart value functions?

 

2 answers

1 accepted

1 vote
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.
Mar 05, 2021 • edited

Hi @Julien Robert 

Yes, that works.  If you remove the quotation marks and extra curly braces that would work.  For example:

{{issue.summary.replace("blah", issue.reporter.displayName)}}

Best regards,

Bill

Hi @Bill Sheboy 

 

Thanks a lot for your answer.

I tried to combine your solution with a variable added by "Create variable" 

Image 111.png

But I failed to use this variable in the replace method. This didn't return anything using the variable whereas it did return something when I directly used values ​​like fieldChange.fromString and fieldChange.toString (the trigger of my action is a change of a field)

Instead of using a custom variable, I used a way to concat "[" and "]" with another topic (https://community.atlassian.com/t5/Jira-questions/Smart-value-with-concatenate-string-in-string-replace-replaceAll/qaq-p/1363587)

Here is my final code that do what I want to do :

{
"fields": {
"summary": "{{issue.summary.replace(fieldChange.fromString.left(0).concat("[").concat(fieldChange.fromString).concat("]"), fieldChange.toString.left(0).concat("[").concat(fieldChange.toString).concat("]"))}}"
}
}

There is probably some way to make it prettier but I stop my search here! 

 

Thanks again !

Like Bill Sheboy likes 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.
Mar 08, 2021 • edited Mar 09, 2021

Hi, and I am glad you got that to work!

Regarding Create Variables, they definitely need some investigation and improvements to be a more useful tool for automation rules.  Currently, I have only found them useful to build JSON strings for complex edits and to remove things from lists (e.g. Components).

Best regards,

Bill

Like # people like this

Thank you

 

Best regards

Julien

Like John Funk likes this

I have discovered a similar issue, where I am unable to use earlier created variables as function arguments in smart values, and the workaround is to use issue entity properties instead:
https://community.atlassian.com/t5/Jira-Service-Management/Re-Pass-in-function-parameters-by-reference-in-smart-val/qaq-p/1806987/comment-id/87452#M87452


For some issue, which has at least 6 comments, automation goes as follows...

Create smart variable:
Variable name: commentNumber
Variable value: 5

Set entity property for issue:
property name: prop_commentNumber
property value (JSON):

{"val": {{commentNumber}} }


Log action:

{{issue.comments.get(issue.properties.prop_commentNumber.val)}}

 
Is it the best approach at this moment, and there is a bug in accessing list elements via smart variable values?

Martin Cleaver
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.
May 30, 2022

Hey Boris,

Did you figure this out?

Thanks

Hi

I am trying to get something similar too. Anyone got this working. I am filtering a list of email address (about 3 or 4) and want to filter out only example.com emails and the string example.com is in a variable domain - I would like to do something like:

 

{{field.split(", ").match("([a-zA-Z0-9_.+-]+@{{domain}})")}}
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.
Sep 13, 2022

Hi @Yatish Madhav 

I just retested this to answer another question: the match() function still cannot accept variables for a regular expression for Jira Cloud. 

And...if you are using Server/Data Center I also doubt this would work as those versions do not have Create Variable with which to make the regular expression dynamic.

Kind regards,
Bill

Thanks for the response @Bill Sheboy  - that is a pity. We are on Jira Cloud.

I wonder if anyone else has got this working or found a workaround apart from hardcoding the domain (or anything else) instead of using the variable.

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.
Sep 14, 2022 • edited

After a bit more research, I found a work-around I created a year ago for this problem, bypassing the need to use the match() function:

  • Create variable with your list of clients. Note the trailing comma to separate all company/client pairs.
    • name: varClientIdList
    • smart value:
 CompanyName1|CL1,CompanyName2|CL2,CompanyName3|CL3,
  • Create another variable for your reporter domain
    • name: varReporterEmailDomain
    • smart value:
 {{issue.reporter.emailAddress.substringAfter("@").substringBefore(".")}}
  • Get the client id using text functions to bracket the domain value, storing it in a variable
    • name: varClientId
    • smart value: 
{{varClientIdList.substringAfter(varReporterEmailDomain.concat("|")).substringBefore(",")}}
  • Use an advanced compare condition to confirm {{varClientId}} has a value before using it.

We couldn't use variables inside .match(), then we just use .replace() before and after the use of .match() because replace accepts variables as input.

i.e.:

Using the field description = "a@a.com,b@b.com,2@a.com,c@c.com"

Automation:

  1. Create variable domains = {{#description.split(",")}}{{split("@").get(1)}}{{^last}},{{/}}{{/}}
  2. For each {{domains.split(",").trim().distinct}} as domain
  3. Create variableA = {{description.replace(domain,"temporal_domain")}}
  4. Create variableB = {{#variableA.split(",").match("(.*temporal_domain)")}}{{.}}{{^last}},{{/}}{{/}}
  5. Create variableC = {{variableB.replace("temporal_domain",domain)}}

Results:

  1. domains = [a.com, b.com, a.com, c.com]
  2. domain:
    1. domain(1) = a.com
    2. domain(2) = b.com
    3. domain(3) = c.com
  3. variableA:
    1. variableA(1) = "a@temporal_domain,b@b.com,2@temporal_domain,c@c.com"
    2. variableA(2) = "a@a.com,b@temporal_domain,2@a.com,c@c.com"
    3. variableA(3) = "a@a.com,b@b.com,2@a.com,c@temporal_domain"
  4. variableB:
    1. variableB(1) = "a@temporal_domain,2@temporal_domain"
    2. variableB(2) = "b@temporal_domain"
    3. variableB(3) = "c@temporal_domain"
  5. variableC:
    1. variableC(1) = "a@a.com,2@a.com"
    2. variableC(2) = "b@b.com"
    3. variableC(3) = "c@c.com"
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.
Feb 06, 2023

Hi @Guido Menardi 

I believe created variables can be used inside the match() function.  The trick is to leave off the outer quotation marks and to let the function assume them around the variable representing the regular expression.

Kind regards,
Bill

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events