Forums

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

Jira Automation : Using Two Smart Values Together

Rick Moerloos April 28, 2023

I have an automation that examines the Labels field values and builds a string based on found labels (ultimately, I want to remove those labels). The first challenge is that if I find fewer labels than the total number of labels, I end up with a trailing comma at the end of my string that I want to remove. 

So, I try to remove the last character from my string, as follows:

 

Smart Value: teamLabels (examines the labels field and builds up a string based on found values):

{{#labels}}{{#if(startsWith("team/"))}}{"remove": "{{.}}"}{{^last}} ,{{/}}{{/}}{{/}}

Problem is that this can leave a trailing comma if there are additional labels. So, I try to remove it. 

Smart Value: teamLen (gets the length of teamLabels - 1)

{{#=}}{{teamLabels.length()}}-1{{/}}

Smart Value: teamLabelsTrim (returns teamLabels with the last char removed)

{{teamLabels.left(teamLen)}}

I have tried multiple variations of the formula for teamLabelsTrim and either Automations can't parse it, or teamLabelsTrim comes back empty. I verified teamLabels and teamLen have appropriate values. 

2 answers

1 accepted

0 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.
April 28, 2023

Hi @Rick Moerloos 

When I tested your first smart value expression for removing the teamLabels it did not leave any trailing commas for several test scenarios.

Would you please post an example where it did leaving a trailing comma? 

Also I recommend writing that expression directly to the audit log as that may confirm if the problem is the input (i.e., labels), the smart value expression, the JSON into which you are inserting that, or something else.  Without seeing your entire rule it is difficult to know.

Kind regards,
Bill

Rick Moerloos May 1, 2023

Given these values in the labels field: 

  • escalation

  • non-team-label

  • team/team-a

  • team/team-b
  • team/team-z
  • zazzle

This smart variable:

{{#labels}}{{#if(startsWith("team/"))}}{"remove": "{{.}}"}{{^last}} ,{{/}}{{/}}{{/}}

Results in this string value:

{"remove": "team/team-a"} ,{"remove": "team/team-b"} ,{"remove": "team/team-z"} ,
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.
May 1, 2023

First thing, thanks for that information as I was able to reproduce the symptom you are seeing!

Next thing: I recommend submitting a ticket to the Atlassian support team for this one.  There appears to be some remaining thing/object after the smart value, list filter, perhaps caused by this syntax using the iterator with an implied target for startsWith(), leading to the extra comma.  I also tried delimiters other than the slash, and those had the same symptom.  You appear to be the site admin for a paid Jira license level, and so you can submit that ticket here: https://support.atlassian.com/contact/#/  Once you hear back from them, please post what they say to benefit the community.

Okay, now for a work-around...

One approach is to remove whatever that stray thing/object is, without the need to do the math on the text-length.  One way is to first save the results in a variable, and then use replaceAll() to only get what you want.  For example:

  • action: create variable
    • name: varTeamList
    • smart value: {{#issue.labels}}{{#if(startsWith("team/"))}}{"remove": "{{.}}"}{{^last}} ,{{/}}{{/}}{{/}}
  • action: use the results, as needed with this
    • {{varTeamList.replaceAll("(.*) ,","$1")}}
Like Peter likes this
Rick Moerloos May 2, 2023

The behavior is expected. I am looping over the labels and building a string based on matched values found. The {{^last}} means that, if I haven't reached the last element in the labels, then add a comma. If there are extra labels that don't match what I'm looking for, those are skipped and I'm left with the dangling comma. 

Example, assuming labels is:

"team/team_a", "not_my_team"

First label found is team/team_a, append to the teamLabels string:

 "remove": "team_a"

Last label? False, so append a comma:

 " ,"

Next label found is "not_my_team", skip. 

Last label? True, so skip adding the comma. 

Result:

"remove": "team_a", 

 

I'll give the workaround a whirl and report back. 

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.
May 2, 2023

Yes, I understand how the last works.  With your iterator structure, the use of last is placed such that there should not be a trailing comma (due to the filter)...unless there is something present.

Rick Moerloos May 2, 2023

Thanks for your help, @Bill Sheboy - this worked:

{{varTeamList.replaceAll("(.*) ,","$1")}}
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.
May 2, 2023

I am glad to learn that helped.  When I wrote that one, I just did some quick testing around your scenario.  Please try the different cases you expect to confirm it works.

0 votes
Clark Everson
Community Champion
April 28, 2023

Hi @Rick Moerloos 

Can you try for the teamLabels.left this instead

Smart Value: teamLabels

{{#labels}}{{#if(startsWith("team/"))}}{"remove": "{{.}}"}{{^last}} ,{{/}}{{/}}{{/}}

Smart Value: teamLen

{{teamLabels.length - 1}}

Smart Value: teamLabelsTrim


{{teamLabels.substring(0, teamLen)}}

It may not work but that's all i got 

 

Best,
Clark

Rick Moerloos May 1, 2023

Given the smartValue teamLabels result:

{"remove": "team/team-a"} ,{"remove": "team/team-b"} ,{"remove": "team/team-z"} ,

This smart variable (teamLen):

{{teamLabels.length - 1}}

Results in an empty value. 

Suggest an answer

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

Atlassian Community Events