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,298,419
Community Members
 
Community Events
165
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?

 

1 answer

1 accepted

1 vote
Answer accepted

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

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

Hey Boris,

Did you figure this out?

Thanks

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS
Community showcase
Published in Jira Software

Upcoming changes to epic fields in company-managed projects

👋 Hi there Jira Community! A few months ago we shared with you plans around renaming epics in your company-managed projects. As part of these changes, we highlighted upcoming changes to epics on...

14,860 views 37 49
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you