Smart value for project openSprint for automation rule

Sam Adams
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 19, 2024

Hi all,
I'm trying to make an automation rule for a Test Case issueType that when any update is made to it the automation rule will look up the current Open Sprint for the project and add a label with that Open Sprint name to the Test Case as a label. The problem is our Test Cases don't use the Sprint field in Jira even though they are under projects that use open sprints. I followed the thread here and came up with the following below:

{

        "update": {

            "labels": [{

                    "add": "{{#lookupIssues.first.sprint}}{{#if(equals(state,"active"))}}{{name}}{{/}}{{/}}"

            }]

        }

}

Unfortunately this did not work for me.
I know the Automation rule itself in general works because I swapped out 

"add": "{{#lookupIssues.first.sprint}}{{#if(equals(state,"active"))}}{{name}}{{/}}{{/}}"

with 

"add": "testLabel"
and that worked just fine when I triggered the rule.

Any other ideas of how I could alter this to get the label name I want?

3 answers

0 votes
Sam Adams
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 20, 2024

Thank you both (@Kalyan Sattaluri @Walter Buggenhout ) for your replies and suggestions.

As requested here is a screen shot of my rule (updated now after your suggestions)

Screenshot 2024-04-20 080039.pngAs you can see I added in @Kalyan Sattaluri new suggested string from @Bill Sheboy 's reply. This unfortunately did not work either :( . 
Also as you can see I also added in the log suggestion at the end of my rule to see what value is being returned.....but when I go to the Log Results it just says

Log Action
Debug message
Log

@Walter Buggenhout , I did briefly try adding

{{#lookupIssues}}{{#sprint}}{{#if(equals(state,"active"))}}{{name}},{{/}}{{/}}{{/}}

to the Labels field directly as an Add but got an "Additional fields contains invalid field(s) in 'update' or 'fields' section: Custom Field Name" error (see below)

Screenshot 2024-04-20 080039.png

Any way thank you both again for your help. Open to suggestions or other things to try. thx

Kalyan Sattaluri
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 20, 2024

@Sam Adams

You should have just started with rule screenshot so we did not have to go back and forth.

As you are not doing lookupIssues action in your rule and your trigger is "Issue updated" and is supplying the issue to the rule, so change your syntax to:

{{#issue}}{{#sprint}}{{#if(equals(state,"active"))}}{{name}}{{/}}{{/}}{{/}}

Log this, and assign to labels using advanced edit. Dont directly update labels field as Sprint name can have spaces and then you will end up with a mess. 

Also, remove "Labels" from the dropdown selection aswell so as to not confuse Jira. You cannot have same field in advanced edit and the dropdown, it will throw an error.

Please confirm and if it works, else share screenshot of audit log. accept my answer in this thread if it works and also vote Bill solution on the other thread so that it surfaces in google search easily. Thanks!

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

Hi @Sam Adams -- Welcome to the Atlassian Community!

As @Kalyan Sattaluri described with the linked thread, that smart value expression must first be put into a created variable, and then parsed to get the distinct values.  Please review the other thread to understand the technique.

Next, when using issue edit for a field, you may select the field or use advanced edit with JSON, but not both methods for the same field edit.  Please remove the Labels field from the dropdown, selected fields in the edit.

Finally, please remove the debug tokens when writing to the audit log: just write the smart value expression.  Debug is used when making a field edit with an expression, although I have rarely found it to be better / worse than just writing to the log.  The only valid use case I would consider is when a rule is approaching the 65 component limit, and so adding other audit log writes is not possible.

Kind regards,
Bill

Like Walter Buggenhout likes this
0 votes
Kalyan Sattaluri
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 20, 2024

Hello @Sam Adams 

Please see grand master @Bill Sheboy 's post HERE:

Basically your syntax should be:

{{#lookupIssues}}{{#sprint}}{{#if(equals(state,"active"))}}{{name}},{{/}}{{/}}{{/}}

But as mentioned by @Walter Buggenhout , log the above value first.

Because depending on your "lookupIssues" logic, you may get more than 1 occurence of same sprint, so as mentioned by Bill in the other thread, you need to save above smart value in a variable and do distinct on it.

Finally because Sprint names can have spaces, you have to to do advanced edit as you are doing but log the JSON first so you know its getting formatted correctly.

Hope it helps and if issues, share your complete rule including JQL and audit log so we can help. Thanks!

 

0 votes
Walter Buggenhout
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 20, 2024

Hi @Sam Adams and welcome to the Community!

For questions like these, please share (screenshots of) your entire automation rule. In the meantime also have a look at:

  • what JQL filter are you using to retrieve the list of issues included in lookupIssues?
  • while you can use the advanced editing option to add a label, it is not necessary. You can also add smart values to the labels field directly with the edit issue action.
  • Use the Log action action to post the result of your complex smart value to the audit log, so you know what it returns:
    {{#lookupIssues.first.sprint}}{{#if(equals(state,"active"))}}{{name}}{{/}}{{/}}

Suggest an answer

Log in or Sign up to answer