Forums

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

Iterate through JQL result of issues, extract certain fields, and send a formatted Slack message

Kristján Geir Mathiesen
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 14, 2025 edited

Hi all

I'm over my head with this ask, that I got last week. Quite specific:

- Every Friday run a JQL query to list up open "Blockers" (scheduled automation rule can do that)

- For each issue, extract the key, Assignee, and Summary

- Send a single Slack message to a shared channel with these 3 fields (1 line per issue) and also tag the Assignee in that line

I've messed around with {{lookupIssues}} but not found a way to format it. Let alone match the Atlassian user ID with Slack user ID...

The Slack message should look something like:

===

Outstanding blockers:

ABC-100 Jane Doe (Slack tagged) Improve the existing API
ABC-101 John Doe (Slack tagged) Finish the new brochure

===

Any ideas?

Takk,
KGM

3 answers

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.
January 14, 2025 edited

Hi @Kristján Geir Mathiesen 

There are two parts to this one: the Slack user ID and the issue field listing.

How many users do you have for Jira and Slack to map to one another? 

  1. When you have just a few, you could use a Lookup Table to map them, using the Jira user's account ID as the key and the Slack ID as the value.  Or, use a long chain of replace() functions.
  2. When you have many users, it may be better to use a separate process to add an entity property for each Jira user, and look them up.  This article describes the method to bulk add them: https://community.atlassian.com/t5/Automation-articles/Mention-someone-directly-in-Slack-via-Jira-Automation/ba-p/1528605

 

That second approach is better for the next step: listing the fields.  The reason is when iterating over the data in the Lookup Issues result, outside data is not visible.  And if the Slack ID is already present for the Assignee data, they can easily be mentioned.

I'm not using Slack a lot currently, so I recommend looking at the necessary formatting in their information.  Perhaps something like this:

{{#lookupIssues}}
* {{key}} - {{summary}} assigned to {{assignee.displayName}} <@{{assignee.properties.metadata.slack_id}}>
{{/}}

 

Kind regards,
Bill

Kristján Geir Mathiesen
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 14, 2025

Takk, @Bill Sheboy ! Love it! I didn't know how to list them up with more than just the issue key.

I think we might only have a few users so I'll look into the Lookup Table

Thanks a million!
KGM

Kristján Geir Mathiesen
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 14, 2025

Sorry, I am not able to access the "Value" in the table (and as you can see in the pictures, I've simplified the value and the Slack message to try to troubleshoot).

What am I doing wrong, @Bill Sheboy ?

SCR-20250114-qarg.png

SCR-20250114-qavf.png

SCR-20250114-qazr.png

Takk, KGM

Kristján Geir Mathiesen
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 14, 2025

I can access the table with

{{nafn.entries}}

and print the results in the Slack message but somehow it doesn't work in the loop/iteration.

Takk again, KGM

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.
January 15, 2025 edited

Hi @Kristján Geir Mathiesen 

My apologies I was not more clear in my original post!  Here is more context to help...

 

Once inside an iterator (e.g., {{#lookupIssues}} ... {{/}} ) only data from the lookup results and lower in scope is visible.  And so the table is not visible.

 

The lookup table approach works for a single issue.  To iterate over the lookup issues the two possible techniques are:

  • a series of chained replace statements for each Jira user-to-Slack ID
    • for example, replace("12345", "ABCDE").replace("67890", "FGHIJ")...
    • This is difficult to maintain and prevent errors
  • using entity properties (But wait, there is a relatively easier way to add these...)

 

To do the entity property method without a lot of hassle you may use a tool to add entity properties or use 2 rules.  Let's go over the 2-rule approach:

  • Use a one-time rule to add the entity property for each user from a lookup table.  This rule could be used when updates are needed for the properties.  That rule could look like this:
  • Update the rule which sends the Slack messages to reference the entity property from the assignee in the issues from the lookup issues result
{{#lookupIssues}}
* {{key}} - {{summary}} assigned to {{assignee.displayName}} <@{{assignee.properties.metadata.slack_id}}>
{{/}}

 

When new people / users are added, the first rule may be updated, run again to refresh the entity properties, and then disabled.

 

UPDATED: I changed the entity property attributes to better align with that earlier article from Atlassian: https://community.atlassian.com/t5/Automation-articles/Mention-someone-directly-in-Slack-via-Jira-Automation/ba-p/1528605

Kristján Geir Mathiesen
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 15, 2025

Thank you so much, @Bill Sheboy  for clarifying. Makes sense now, after all my testing yesterday and not getting any value from the table. I had concluded that this code wasn't getting the value from the table at all.

So you are suggesting that the "extra" rule add a new attribute/property to our Atlassian user profile called "slack_id" and populate that. This attribute is then accessible within the iterator loop {{#lookupIssues}} ... {{/}}  yes?

Takk, KGM

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.
January 15, 2025

Yes, that is correct.

That first rule takes the place of the bulk-loading suggested in the article by @Daniel Eads and would work for a smaller number of users (although requires manually entering values in the table).

Kristján Geir Mathiesen
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 17, 2025

Thank you again, @Bill Sheboy  for all your help. If I may ask, does the field/property:

slack_id

exist already on the Atlassian user profile or do we have to create it somehow?

Takk, KGM

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.
January 17, 2025

I do not believe it exists by default, and I just did a quick test with my free-license site to confirm that.  You may do the same by:

  • identify your user's account ID
  • enter this URL in a browser tab to load the entity properties
    • yourJiraURL/rest/api/3/user/properties?accountId=yourAccountId
  • search on the page for slack_id

And...we are adding the entity property under the metadata one to reduce the risks of collision and keep things nicely organized.  For example, if other properties were added for the user by the customer.

Kristján Geir Mathiesen
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 23, 2025

Thank you again, @Bill Sheboy , for all your help! I ended up using an Automation rule to populate my zslackid property on the Atlassian users:

SCR-20250123-lukq.png

Have a great day! KGM

Like Bill Sheboy likes this
0 votes
Kristján Geir Mathiesen
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 14, 2025

Or you, brother @Darryl Lee ?

0 votes
Kristján Geir Mathiesen
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 14, 2025

Hey @Bill Sheboy  Any ideas?

Takk, KGM

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
atlassian, atlassian government cloud, fedramp, webinar, register for webinar, atlassian cloud webinar, fedramp moderate offering, work faster with cloud

Unlocking the future with Atlassian Government Cloud ☁️

Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.

Register Now
AUG Leaders

Atlassian Community Events