Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Using Smart Variables as function parameters in automations - does not work

Boris Zozoulia September 16, 2021

Trying to figure out how to pass in smart variable value when defining another smart variable referencing some function parameter. 

For example:
I have an issue with 10 comments.

Given  smart variable:

commentNumber = 5

How to extract this comment from {{issue.comments}}?


I have tried creating smart variable with value

{{issue.comments.get(commentNumber)}} no data is returned

I have also tried {{issue.comments.get({{commentNumber}})}}

But automation returns an error in execution

 

The example above is somewhat arbitrary, and I do not need to hardcode comment Number, since it is calculated dynamically.


UPDATE:

there is actually a Bug Report on this:
https://jira.atlassian.com/browse/JRACLOUD-75659

2 answers

1 accepted

5 votes
Answer accepted
Boris Zozoulia September 16, 2021

Hmm, it appears, by using issue entity properties, list elements can be extracted properly!


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?

Brock Jolet September 20, 2021

I was really hopeful to use this workaround for a similar issue, but my variable is a date and doesn't seem to translate.

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 20, 2021

Hi @Brock Jolet 

Have you tried changing the date into one of the other formats before storing it?  You can then convert it back with toDate later.

https://support.atlassian.com/jira-software-cloud/docs/smart-values-date-and-time-functions/#Smartvaluesdateandtimefunctions---

Kind regards,
Bill

Lauren Benson November 9, 2023

@Boris Zozoulia thank you so much for this!!  I was able to use it to work around not being able to loop through smartVariable lists to create issue content.  I wanted to share how I used it.  Obviously this workaround only works for short lists and where the two lists are the same length. 


Note: the lists are created using {{ issue.description.match("(capture_group)")}} and therefore vary in length depending on the number of matches.

Create smart variables:
Variable name: List1
Variable smartValue: {{ description.match("(capture_group1)") }}
Variable value: 12345, 22345, 33345

Variable name: List2
Variable smartValue: {{ description.match("(capture_group2)") }}
Variable value: xxxxx, yyyyy, zzzzz

Set entity property for issue:
Property name: Lists
Property value (JSON):
{ 
"ListOne": [ {{ List1 }} ],
"ListTwo": [ {{ List2 }} ]
}

Create another smart variable:
Variable name: countOfItems
Variable smartValue: {{ issue.properties.Lists.ListOne.size }}
Variable value: 3


Create actions based on list length:
IF {{countOfItems}} == 1
THEN add new comment: 
List1 Val: {{ properties.Lists.ListOne.get(0) }} List2 Val: {{ properties.Lists.ListTwo.get(0) }}
Result
List1 Val: 12345 List2 Val: xxxxx

ELSE IF {{countOfItems}} == 2
THEN add new comment
List1 Val1: {{ properties.Lists.ListOne.get(0) }} List2 Val1: {{ properties.Lists.ListTwo.get(0) }} 
List1 Val2: {{ properties.Lists.ListOne.get(1) }} List2 Val2: {{ properties.Lists.ListTwo.get(1) }}
Result
List1 Val1: 12345 List2 Val1: xxxxx
List1 Val2: 22345 List2 Val2: yyyyy

and so on....
0 votes
Boris Zozoulia September 16, 2021

Oh, I found a confirmation of a similar issue by another user.

It appears you cannot use smart variable values in passing in as function arguments when constructing other smart variables.

Thanks, @Julien Robert for confirming my finding (half a year ago ;)

@John Funk @Bill Sheboy 

https://community.atlassian.com/t5/Jira-Software-questions/Re-Re-Using-variables-in-functions-in-smart-values-in-J/qaq-p/1631958/comment-id/127093#M127093

That is really a limitation

Boris Zozoulia September 16, 2021

@Bill Sheboy Have just discovered you mentioned this bug previously:
https://community.atlassian.com/t5/Jira-articles/Automation-for-Jira-Create-variable-New-component/bc-p/1536036#M3594

Greetings, community!  Quick tip: created variables do not appear to work as inputs to functions, such as:

{{issue.description.replace(myVariable, "my new text")}}

What happens is the variable evaluates to null and collapses the function, even when you add null handling.  Maybe there is something up with the typing of the created variables which does not allow them to be resolved.  I am submitting a defect for this so Atlassian has visibility of the issue.


Mind sharing the jira bug report on 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.
September 16, 2021

Hi @Boris Zozoulia 

Thanks for that work-around with entity properties!  Now just got remember to keep those cleaned up when used as temps.  :^)

You will not be able to see the defect my company submitted, but here are the public backlog ones for it:

https://codebarrel.atlassian.net/browse/AUT-2022
https://jira.atlassian.com/browse/JRACLOUD-75659

Kind regards,
Bill

Like Boris Zozoulia likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events