Forums

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

How can I filter for multiple issue types while sending a slack message using jira automation?

Lewis Smith July 21, 2023

I am currently using this logic to filter for issues within an issue lookup to filter for the bug tickets.

{{#lookupIssues}}
   {{#if(equals(issueType.name, "Bug"))}}
Bug Fixes:
   • {{key}} - {{summary}}
   {{/}}
{{/}}

However I cannot find a way to filter exactly like this but for all tickets that are NOT the "Bug" issue type.

I feel I am missing something obvious, I tried a lot of docs online but found nothing to work.

How would I do this so I can separate them into different lists when sending one message in Slack? Thanks! 

1 answer

1 accepted

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

Hi @Lewis Smith -- Welcome to the Atlassian Community!

A couple of ways to do this are to use either the NOT() operation around your current condition, or to use the OR() operation to test the other issue types.  (Please note: this version of OR() only accepts 2 parameters, and so chaining is needed, such as OR(A, OR(B,C))

https://support.atlassian.com/cloud-automation/docs/jira-smart-values-conditional-logic/#not

https://support.atlassian.com/cloud-automation/docs/jira-smart-values-conditional-logic/#or

Once you have figured out your filtering, just add the sections to your Slack message:

...bug info
...non-bug info

Kind regards,
Bill

Lewis Smith July 23, 2023

Thank you for your reply! 

It seems this was the solution after all, I was just doing it wrong in terms of my formatting. I am now able to filter for both of these how I would like! 

I am now wondering if you could help me expand on this so I could further my query.

I really want to make this only return something if the issue count of "Bug" or not "Bug" is > 0 or perhaps if there is 0 of this issue type then return something else.

for example:

{{#lookupIssues}}
   {{#if(equals(issueType.name, "Bug"))}}
Bug Fixes:
   • {{key}} - {{summary}}
else
   There are no bugs this time. 
   {{/}}
{{/}}
 

OR 

{{#lookupIssues}}
   {{#if(equals(issueType.name, "Bug") AND issues.size > 0)}}
Bug Fixes:
   • {{key}} - {{summary}}
   {{/}}
{{/}}

Could you help me with how I would achieve this? Thank you! 

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.
July 23, 2023

Unfortunately, I do not believe that is possible with a single operation / lookup.

Fortunately, you are using Jira Cloud, and so may use the Create Variable action to help, although there are a few ways to do this.  Also, {{lookupIssues.size|0}} will return the count of issues returned by the lookup.

Thus one way to do this is to capture the two filter results in created variables, and just use them:

  • use the lookup issues action
  • create a variable
    • name: varBugs
    • value: {{#lookupIssues}}{{#if(equals(issueType.name, "Bug"))}}{{key}} - {{summary}};{{/}}{{/}}
  • if/else condition
    • test if {{varBugs}} is empty
      • re-create the variable to replace the value
        • name: varBugs
        • value: There are no bugs this time.
  • create another variable
    • name: varNotBugs
    • value: {{#lookupIssues}}{{#if(not(equals(issueType.name, "Bug")))}}{{key}} - {{summary}};{{/}}{{/}}
  • if/else condition
    • test if {{varBugs}} is empty
      • re-create the variable to replace the value
        • name: varBugs
        • value: There are no bugs this time.
  • send your message, just using {{varBugs}} and {{varNotBugs}}, splitting on the semicolon, like this
    • {{#varBugs.split(";")}}* {{.}}{{/}}
    • {{#varNotBugs.split(";")}}* {{.}}{{/}}

You may need to experiment until you get the formatting you want.

 

Another way to do this is with 2 calls to lookup issues: call once to get bugs, and save the formatted results in a variable.  Later test the size to replace with the "no bugs..." message.  And repeat that for the "not bugs" ones.

Lewis Smith July 24, 2023

Thanks for the reply! 

I tried what you said and it's not working due to the following error:
Screenshot 2023-07-24 at 10.15.23.png

 

Here is the rule I have set up, hopefully this can help.
Screenshot 2023-07-24 at 10.15.54.pngScreenshot 2023-07-24 at 10.16.09.png

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.
July 24, 2023

That error means that an action/condition/branch is referencing the {{issue}} smart value but you do not have any...or...there is a type and the rule interprets a smart value that way.

I found a typo in my suggestion when creating the varNotBugs variable...which I fixed in my earlier post.  (It was missing a parenthesis.)  Please check that one first to see if that corrects this error.

Lewis Smith July 24, 2023

I have updated the logic as you said and I am still getting that error, I also get another error with the variable value.


See here:
Screenshot 2023-07-24 at 15.25.31.png

 

This is only fixed when I do this:Screenshot 2023-07-24 at 15.25.49.png

 

Is this correct or am I perhaps doing something wrong here also? Thank you so much! 

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.
July 24, 2023

Sorry I missed that closing section to match up!

Is the rule saving?

If so, and the error occurs when the rule runs , please post an image of the audit log details for the run...showing all the information including the error.

Lewis Smith July 24, 2023

I have managed to fix these errors by changing the if conditions to the following:

Screenshot 2023-07-24 at 16.28.23.png

Now it seems that it works to some degree but does not output the updated variable inside the IF of "No bug" when there is no issues but instead just leaves it blank on the output.

I am also having issues with the formatting as I would like to get each issue onto a new line but I cannot seem to get this to work either. 

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.
July 25, 2023

Please show the updated block of actions for "no bug", where you:

  • create the variable
  • if/else on the condition
    • re-create the variable

 

For the formatting, you may need to try adding a \n for a new line character after each one or to switch to HTML formatting.  Would you post an image of the current message action and what the output in Slack looks like now?

Lewis Smith July 25, 2023

No problem here is the up to date info you requested. 

Here is the rule breakdown:

Screenshot 2023-07-25 at 15.57.41.pngScreenshot 2023-07-25 at 15.57.52.png

 

Here is the variable I make at first:Screenshot 2023-07-25 at 16.02.26.png

 

Here is the variable after it should be updated:Screenshot 2023-07-25 at 15.58.45.png

 

 

Here is the format of the message being sent to Slack:Screenshot 2023-07-25 at 15.58.13.png

 

 

And here is the final outout:Screenshot 2023-07-25 at 16.04.09.png

 

Thank you! 

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.
July 25, 2023

Rather than using this in the expression:

{{.}}{{"\n"}}

Perhaps try this

{{.}}\n

So, without the quotation marks and curly brackets.

Lewis Smith July 25, 2023

I have now tried this and the output is as follows: 
Screenshot 2023-07-25 at 16.16.14.png

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.
July 26, 2023

Hi, Lewis.

After testing a bit I was unable to find a way to get the conditional newline to work in a created variable with markup.

An alternative is to use the variables only for counting issues, and then use that to show your "there are no bugs" messages.  This is a variant of what I described earlier, as it uses math operations to count the values in a condition.

  • action: lookup issues to get all the issues
  • action: create variable, named varBugCount with a value of below.  This adds a 1 for each matching issue found.
{{#=}}0{{#lookupIssues}}{{#if(equals(issueType.name,"Bug"))}}+1{{/}}{{/}}{{/}}
  • action: create variable, named varNoBugCount with a value of 
{{#=}}0{{#lookupIssues}}{{#if(not(equals(issueType.name,"Bug")))}}+1{{/}}{{/}}{{/}}
  • action: write your message, getting any issues from the lookup, and then conditionally adding the "none" messages
The bugs are:
{{#lookupIssues}}{{#if(equals(issueType.name,"Bug"))}}
* {{key}} - {{summary}}
{{/}}{{/}}
{{#if(equals(varBugCount,"0"))}}There are no bugs.{{/}}

The not bugs are:
{{#lookupIssues}}{{#if(not(equals(issueType.name,"Bug")))}}
* {{key}} - {{summary}}
{{/}}{{/}}
{{#if(equals(varNotBugCount,"0"))}}There are no not-bugs.{{/}}

 

The reason the zero-count checks AND outputs cannot be done together is inside of an iterator like {{lookupIssues}} ... {{/}}, you cannot refer to anything other than the fields of the lookup.

Like Lewis Smith likes this
Lewis Smith July 27, 2023

Wow thank you so much, this whole process has helped me understand jira automation a lot more but this is the perfect solution for exactly what I wanted! 

I think we can close this off now as that is 100% working! 

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

As there is no comprehensive documentation for automation rules, experimentation is often needed to figure things out  :^)

I encourage you to create a test project in Jira, just for testing / playing around with automation rules.  This can help to build and test complicated rules, and then copy them over to the desired project when ready.

Suggest an answer

Log in or Sign up to answer