Specifying a field value to be retuned for a Smart Value lookup

Keith Vedol October 14, 2022

Hi,

I am working on a release notification email that includes items that are separated by categories.  Is there a way to return only the value specified for the smart value provided?  For example, if the category values include:

  • Bug
  • Improvement
  • Feature

Would there be a way to specify which one to return?  Currently it returns all with the following:

{{#lookupIssues}}{{customfield_10530}}

..and it would be nice to have it get the specified value instead of the entire list to separate the categories based on the email template being used which has separated scetions based on the issue category.

 

I have tried many functions listed in some of the documentation though none have worked thus far.

Any advice would be appreciated.  Thanks.

2 answers

0 votes
John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 18, 2023

Hey @Keith Vedol  - did you get this solved? 

0 votes
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.
October 15, 2022

Hi @Keith Vedol 

When you have known criteria for your groups, such as Issue Type, there are at least two ways to do this:

  1. Use smart value, list filtering to get the detailed issues meeting your criteria, while only calling Lookup Issues once.  Please look here for more information: https://community.atlassian.com/t5/Automation-articles/Filtering-smart-value-lists/ba-p/1827588
  2. When you need both the issue details and summation for the selected issues, try calling Lookup Issues with different JQL for each group, and store the results you need in a Created Variable for use later in the rule, such as in your notification email.

Kind regards,
Bill

Keith Vedol October 16, 2022

Hi @Bill Sheboy 

I tried one of the examples in the documentation you linked me to with changes to look for the custom field value and no results are returned:

{{#issue.customfield_10530}}
{{ #if(customfield_10530, "New Feature")}}{{key}}{{ / }}

and another (exists and non-exists):

{{#issue.customfield_10530}}
{{
#if(not(exists(name.match("(/New Feature/g)"))))}}{{key}},{{/}}{{/}}

{{#issue.customfield_10530}}
{{#if(exists(value.match("(/New Feature/g)")))}}{{key}},{{/}}{{/}}

 

I have replaced 'name' with 'value,' and 'defaultValue' to no avail.

I would just like the issues that contain this value in the custom field returned as a list and it is proving to be quite the task to do so.

 

The documentation only discusses how to return a comment body, but doesn't go into detail of how to return different values such as key, summary, description, etc.

 

Is there something I am missing here?  Also I think the documentation could be updated to provide better examples for those who are newer to using smart values.  Thanks.

 

Also, for point 2, do you mean having 3 {{#lookupIssue}} actions in one rule with one being for each category such as: (ex. fixVersion = '{{version.name}}' AND "Category[Dropdown]" = "New Feature" ORDER BY cf[10530] ASC, key ASC) and so on?

And if so, after each Lookup component I would need to add a Create Variable component?

 

test_notification.jpg

 

Regards,

Keith

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.
October 17, 2022

First thing, it is helpful to use this how-to article to confirm you have the correct smart values for your fields: https://support.atlassian.com/cloud-automation/docs/find-the-smart-value-for-a-field/

Next, please try using the filtering on the lookup issues results, not on the individual issue.  Something like this for some HTML in an email with keys and summary as URLs:

Here is the list:
<ul>
{{#lookupIssues}}
{{#if(equals(customfield_10530.name,"New Feature"))}}<li><a href="{{url}}">{{key}} - {{summary}}</a></li>{{/}}
{{/}}
</ul>

And...you should be able to reference any of the fields this way.

For option #2, yes...You would call lookup issues with different JQL, storing the results in a created variable as HTML, and then just include those in the email.

Keith Vedol October 17, 2022

Hi @Bill Sheboy

The first option worked as I am now able to separate them accordingly (Thanks!).  Is there a way to return a string if no issues were found for that value as opposed to being blank (ex. "No items matching that value were found.")

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.
October 17, 2022

Yes, I believe this would do that when using Lookup Issues as the source of issues.  Just put this as a separate section, or use conditional logic to build the content in a created variable

{{#if(equals(lookupIssues.size|0,0))}} No items matching that value were found {{/}}
{{#if(lookupIssues.size.gt(0))}}
Here is the list:
<ul>
{{#lookupIssues}}
{{#if(equals(customfield_10530.name,"New Feature"))}}<li><a href="{{url}}">{{key}} - {{summary}}</a></li>{{/}}
{{/}}
</ul>
{{/}}

How this works:

  • Check the number of items in the lookup (i.e. size) with a default value of 0, and compare that to zero
  • When none are found, return your text string.
  • When there are more than 0, show your list
Keith Vedol October 17, 2022

Hi @Bill Sheboy

Using the code provided, I get an empty section:

 

{{#if(equals(lookupIssues.size|0,0))}} <b><span
style='font-size:9.0pt;font-family:Montserrat;color:white'>No fixes were included in this release.</span></b></p> {{/}}
{{#if(lookupIssues.size.gt(0))}}
<ul>
{{#lookupIssues}}
{{#if(equals(customfield_10530.value,"Test"))}}<li><a href="{{url}}">{{key}} - {{summary}}</a></li>{{/}}
{{/}}
</ul>
{{/}}

 

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.
October 17, 2022

Okay, I just tried that with a couple of different custom fields (text and single-select) and it worked for me.  Let's try some diagnosis...

(A) What is the type of your custom field?

 

(B) When you write the following to the audit after a lookup issues action, what do you observe?

{{#lookupIssues}}{{key}}:{{customfield_10530}}{{^last}}, {{/}}{{/}}

 

(C) When you write the following to the audit after a lookup issues action, what do you observe?

{{#lookupIssues}}{{key}}:{{customfield_10530.value}}{{^last}}, {{/}}{{/}}

 

Thanks!

Keith Vedol October 17, 2022

Hi,

A) The field type is single-select dropdown.

B)  {{#lookupIssues}}{{key}}:{{customfield_10530}}{{^last}}, {{/}}{{/}} produces all 8 issues in question covering the different category types.

TESTDNA-1:New Feature, TESTDNA-37:New Feature, TESTDNA-22:Improvement, TESTDNA-8:Bug/Defect, TESTDNA-26:Bug/Defect, TESTDNA-35:Bug/Defect, TESTDNA-21:Technical Debt, TESTDNA-34:Technical Debt 

C)  {{#lookupIssues}}{{key}}:{{customfield_10530.value}}{{^last}}, {{/}}{{/}} produces the same result:

TESTDNA-1:New Feature, TESTDNA-37:New Feature, TESTDNA-22:Improvement, TESTDNA-8:Bug/Defect, TESTDNA-26:Bug/Defect, TESTDNA-35:Bug/Defect, TESTDNA-21:Technical Debt, TESTDNA-34:Technical Debt 
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.
October 17, 2022

Thanks for those tests!  They verify we have both the correct smart value and references to its attributes.

Now your prior test was checking for a value of "Test", and I do not see that as one of your options.  In only see: New Feature, Improvement, Bug/Defect, and Technical Debt.

Please try to change "Test" to one of those values.

Keith Vedol October 17, 2022

Using Technical Debt and having no issues with that category, I still get blank return.

 

{{#if(equals(lookupIssues.size|0,0))}} <b><span
style='font-size:9.0pt;font-family:Montserrat;color:white'>No fixes were included in this release.</span></b></p> {{/}}
{{#if(lookupIssues.size.gt(0))}}
<ul>
{{#lookupIssues}}
{{#if(equals(customfield_10530.value,"Technical Debt"))}}<li><a href="{{url}}">{{key}} - {{summary}}</a></li>{{/}}
{{/}}
</ul>
{{/}}
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.
October 18, 2022

Let's try to rule some more things out...

What is the JQL you are using for your Lookup Issues, and if you use that stand-alone does it return what you expect?

Is the value "Technical Debt" correct, or are there any leading/trailing spaces in the drop-down list value?

Have you tried a value other than "Technical Debt"?

And, let's try this with no HTML formatting, like this:

{{#if(equals(lookupIssues.size|0,0))}}No fixes were included in this release.{{/}}
{{#if(lookupIssues.size.gt(0))}}{{#lookupIssues}}{{#if(equals(customfield_10530.value,"Technical Debt"))}}{{key}} - {{summary}}{{/}}{{/}}{{/}}

Keith Vedol October 18, 2022

The JQL being used is fixVersion = '{{version.name}}' ORDER BY cf[10530] ASC, key ASC.

 

I have tried 'Improvement' as well with same result.

 

Using the snippet above with no HTML returns blank email.

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.
October 18, 2022

The only other suggestion I have is the rule is "glitched"...sometimes rules get broken by adding/removing components after too many edits.

Try disabling this rule, and re-create it from scratch to see the impact.

If that still does not help, I suggest submitting a ticket to Atlassian Support to take a look as they have access to logging customers cannot see.  You are the site admin on a paid Jira license and so can do that here: https://support.atlassian.com/contact/#/

I recommend including a link to this thread so they can see what has been tried thus far, and when you hear back from them, please post what you learn.  Thanks!

Keith Vedol October 18, 2022

Ok it didn't work with a new rule and the above code snippet only.  The code:

{{#if(equals(lookupIssues.size|0,0))}}No fixes were included in this release.{{/}}

just seems to be ignored completely even when used by itself.

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.
October 18, 2022

Just a hunch...would you please post an image of your complete rule one more time?  Perhaps we are missing something obvious in the rule's structure/order of components.

Keith Vedol October 18, 2022

releasetest.jpg

This is the simplified version (newly-created rule).

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.
October 18, 2022

Before the send email action, please write this to the audit log and note the results:

Count of issues is: {{lookupIssues.size|0}}

So your rule would be:

  • trigger: version released
  • action: lookup issues
  • action: write to audit log
  • action send email
Keith Vedol October 18, 2022

Results below (still blank email):

releasetest.jpg

 

Note that when I change the code to this:
{{#lookupIssues}}
{{#if(equals(lookupIssues.size|0,0))}}No fixes were included in this release.{{/}}
{{#if(lookupIssues.size.gt(0))}}{{#if(equals(customfield_10530.value,"Improvement"))}}{{key}} - {{summary}}{{/}}{{/}}{{/}}

 

I get this in the email:

No fixes were included in this release. No fixes were included in this release. No fixes were included in this release. No fixes were included in this release. No fixes were included in this release. No fixes were included in this release. No fixes were included in this release. No fixes were included in this release.

 

So with the change, it send a message for each one it checks and doesn't find the desired value.

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.
October 18, 2022

I would advise against testing the full {{lookupIssues}} inside of iterating on that...which I why I split it into the two parts: no issues found and some issues found.

And...I think I figured this out: are you using a team-managed project (TMP) or company-managed project (CMP)?

When testing with CMP it worked for me...but I just ran the same test with TMP and smart value list filtering does not work.  Which means you have discovered a bug, and I recommend submitting that to Atlassian support.

Your work-around is to use separate lookup calls, one by one with JQL meeting your needs, and saving the results in created variables.  Then reference the variables in your email body.

Keith Vedol October 18, 2022

The test project being used is CMP.

 

With the workaround how would that change the snippet you provided?  Sorry for all of the question but I was hoping this would work as expected according to documentation and the examples you provided.  I only did one so far and hoping I am on the right track before I continue.  So I would need to create another lookup and variable after the first variable is created as shown below correct?

 

variabletest.jpg

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.
October 18, 2022

You are on the correct track...And if the original is not working for you with CMP there is still a problem with your rule/Jira site, which I suggest you report.

 

The work-around pattern would be this:

  • action: lookup issues with JQL for a specific category, such as Improvement
  • action: create variable
    • name: varImprovement
    • smart value: <ul>{{#lookupIssues}}<li>{{key}} - {{summary}}</li>{{/}}</ul>
  • repeat for each category...
  • action: send email
    • body:
Improvements:
{{varImprovement}}
Bugs:
{{varBugs}}

First get that to work, showing all categories. 

Then you can add some conditional processing, such as below...including handling the case of no issues:

{{#if(exists(varImprovement))}}
Improvements:
{{varImprovement}}{{/}}
{{#if(exists(varBugs))}}Bugs:
{{varBugs}}{{/}}

 

 

Keith Vedol October 18, 2022

Ok I got them to appear with:

{{#if(exists(varFeature))}}
Features:
{{varFeature}}{{/}}
{{#if(exists(varImprovement))}}
Improvements:
{{varImprovement}}{{/}}
{{#if(exists(varBug))}}
Bugs:
{{varBug}}{{/}}

 

I am getting closer with this:


{{#if(equals(varFeature.size|0,0))}}<b>No new features were included in this release</b>.{{/}}
{{#if(exists(varFeature))}}
{{varFeature}}{{/}}



However, it will return the message even when issues matching the category are found:

No new features were included in this release.

TEST-1 New Feature 1

TEST-2 New Feature 2

 

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