Forums

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

Automation - Unable to filter JQL results for custom field email notification

jalewis March 23, 2023

I've successfully created a JIRA rule to send an email notification based on a JQL query. I then applied #IF statement in the email notification to filter by specific fields. During testing I found filtering via #IF only works on core fields, not custom fields. 

Below is the script I use. I'm able to filer by status.name, but that same functionality does not apply to issue.customfield_16276.value. I'm looking for a solution to the filtering issue or a workaround to generate the same result. The custom field in this scenario is used in the JQL query just as an FYI. Thoughts?

Development --- this works
{{#lookupIssues}}
{{#if(status.name.startsWith("Development"))}}
<a href="{{url}}">{{key}}</a> {{summary}}
{{/}}
{{/}}

Done --- this works
{{#lookupIssues}}
{{#if(status.name.startsWith("Done"))}}
<a href="{{url}}">{{key}}</a> {{summary}}
{{/}}
{{/}}

Test Alert --- this does not work
{{#lookupIssues}}
{{#if(issue.customfield_16276.value.startsWith("Amber"))}}
<a href="{{url}}">{{key}}</a> {{summary}}
{{/}}
{{/}}

jira_automation.jpg

1 answer

1 accepted

1 vote
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.
March 26, 2023

Hi @jalewis -- Welcome to the Atlassian Community!

First thing...When you are inside of an iterator like {{#lookupIssues}} {{/}} you do not use the issue. prefix.  That would be trying to reference something outside of the lookup, and so may not work as you expect.  Please try removing that to see what happens.

Next, what is the type of your custom field?  If it is single selection, you can just check value.  However if it is multiple select, you will need to either join all of the values together for the check, or use nested iterators.

If neither of those works, please let me know and we can try some other work-arounds using created variables.

Kind regards,
Bill

jalewis March 27, 2023

Hi Bill, thanks for the reply. I'm still unable to get the JQL results to filter by a custom select field in my example. I removed the issue portion from the script as shown below:

Test Alert --- this does not work
{{#lookupIssues}}
{{#if(customfield_16276.value.startsWith("Amber"))}}
<a href="{{url}}">{{key}}</a> {{summary}}
{{/}}
{{/}}

The custom field is a single selection field with the following values, Green, Amber, Red. Is there a different way to check the value? Maybe something with equals?

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.
March 27, 2023

Okay, let's confirm the custom field contains what you expect first.  Please add an action to write this to the audit log after your lookup issues action:

{{#lookupIssues}}{{customfield_16276.value}}{{^last}}; {{/}}{{/}}

That should produce a list of your custom field values, separated by semicolons.  If you see anything else, either the field id is incorrect or it contains something unexpected.

jalewis March 28, 2023

I was able to confirm a list of statuses using the query above. How do I use this information to filter the list of issues by Amber?Capture.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.
March 28, 2023

Ah...something is different with this one, as that "value" may be an object and not a text value.  Otherwise it could not possibly display those icons with the data...

Or do your drop-down values contain icons at the front of each value?

If they have the icons, you may want to try endsWith() instead of startsWith()

jalewis March 28, 2023

You are the man Bill. I made that change and was able to filter my issues by Amber. Just to recap for anyone following:

  • I was unable to filter a custom field in an automated email
  • After consulting Bill, it was determine drop-down had icons in front of each value
  • By updating startsWith() to endsWith(), the issue filter worked.

Below is the revised code used in the automation email and a screenshot of the final result. Thanks again Bill.

Issues in Development
{{#lookupIssues}}
{{#if(status.name.startsWith("Development"))}}
{{fields.customfield_16276}} <a href="{{url}}">{{key}}</a> {{summary}}
{{/}}
{{/}}

Completed Issues
{{#lookupIssues}}
{{#if(status.name.startsWith("Done"))}}
{{fields.customfield_16276}} <a href="{{url}}">{{key}}</a> {{summary}}
{{/}}
{{/}}

Red Alert Issues
{{#lookupIssues}}
{{#if(customfield_16276.value.endsWith("Amber"))}}
{{fields.customfield_16276}} <a href="{{url}}">{{key}}</a> {{summary}}
{{/}}
{{/}}

jira_automation_2.jpg

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

Awesome!  I am glad that worked  :^)

Suggest an answer

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

Atlassian Community Events