Automation to collect details to create release notes when a fix version is deployed
Asked by John Maner:

Background {#toc-hId--436574763}
--------------------------------

I, a very green Automation user, am trying to use the Jira Automation plugin to gather details from issues and send them to different email distributions which are based on a component in the issue.

For context, we have a few different api's utilized by different clients. E.g., flavor 1 is utilized by clients A, B, and C, flavor 2 is utilized by clients D, E, F. When we release a version with changes to flavor 1 I want to collect the value from a custom property and send them in an email to a distribution which contains info for clients A, B, C. I would like it if the automation could do this for N (well, up to 200 since I would like to use the lookup table), flavors. It seems like I could get around this by instead creating N different rules for each specific flavor, but this quickly becomes tedious to maintain.

Based the on actions I have available, I want to be able to do the following.

* When: Version released
* Then: Create lookup table with keys that correspond to the api flavor and values that correspond to the email distribution for that group of clients.
* For each: api flavor
  * If count of issues in this version \> 0
  * then send email to email distribution for api flavor (based on value in lookup table) with subject of version and content is a bulleted list of the custom property of the change summary

The Problem (in my understanding, or a limitation?) {#toc-hId-2050938070}
-------------------------------------------------------------------------

**Are we able to loop over the Key in a custom lookup table?**

**Are we able to access the corresponding Value in a custom lookup table while using a branch/loop?**

**Is this approach even feasible??!! Am I really better off just creating N individual rules to handle this?**

My Attempt {#toc-hId-243483607}
-------------------------------

#### When: Version released {#toc-hId--862906278}

Easy enough... ![fix version.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/279433i8965036AAFD82F62/image-size/large?v=v2&px=999 "fix version.PNG")

#### Then: Create lookup table {#toc-hId-1624606555}

Easy enough...

![create lookup table.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/279432i3E56F407C6589307/image-size/large?v=v2&px=999 "create lookup table.PNG")

#### For each: Smart Value {#toc-hId--182847908}

**How can we iterate over the key a lookup table?**

![branch on lookup table..PNG](https://community.atlassian.com/t5/image/serverpage/image-id/279434iDC6968B4EDCB675C/image-size/large?v=v2&px=999 "branch on lookup table..PNG")

Assuming we can, we will proceed...

#### Then: Lookup issues {#toc-hId--1990302371}

Gather all issues using lookup issues JQL where apiflavor property is our custom apiFlavor smart value we are trying to iterate over, and the issue is in our version. Should probably also include a filter for ticket status and resolution...

![lookup issues.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/279435i99A1FE11B77CF8F4/image-size/large?v=v2&px=999 "lookup issues.PNG")

#### If: Compare two values {#toc-hId-497210462}

Only continue if there are issues for this flavor so we don't spam our clients with blank emails...

![more than 0 issues for this flavor.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/279438i96DC39FF11011BCE/image-size/large?v=v2&px=999 "more than 0 issues for this flavor.PNG")

#### Then: Send email {#toc-hId--1310244001}

I would like to pull the value, the email address, from the lookup table. Though I am not sure if this is possible.

![send email.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/279439i706E0518508067B3/image-size/large?v=v2&px=999 "send email.PNG")

As a kicker, I'd also like to send a notification to myself and our deployments group so they are aware that clients have been notified.

![also email me.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/279444iE1B5B44AE7ED8178/image-size/large?v=v2&px=999 "also email me.PNG")


Answers:
author: Darryl Lee
body: Hi [@John Maner](/t5/user/viewprofilepage/user-id/4128907) -

I don't think there is a **.keys** function for Lookup Tables. That would be pretty sweet.

Instead, I'm thinking you'll have to make a smart value variable with your keys (flavor-1,flavor-2...), and then use **.split(",")** to iterate through them.

Ah yeah, this seemed to work:

![Screenshot 2023-09-07 at 9.41.59 PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/279470iCC771C4E3956676F/image-size/large?v=v2&px=999 "Screenshot 2023-09-07 at 9.41.59 PM.png")

NOW, before you kill yourself trying to create 200 entries in the lookup table ***by hand*** (and then also creating that {{keys}} variable manually), I would implore you to take a look at my olde article, [Hacking/Parsing Automation Rules with JSON for Fun and Profit.](https://community.atlassian.com/t5/Automation-articles/Hacking-Parsing-Automation-Rules-with-JSON-for-Fun-and-Profit/ba-p/1984033)

It's been a while for me, so I looked at the rule I just created, and thankfully, a Lookup Table should be pretty easy to programmatically generate, the key pieces of it being this:

```
          "type": "jira.create.mapping-variable",
          "value": {
            "name": {
              "type": "FREE",
              "value": "apiFlavorEmails"
            },
            "mappings": [
              {
                "key": "flavor-1",
                "value": "flavor-1-deployments@email.com"
              },
              {
                "key": "flavor-2",
                "value": "flavor-2-deployments@email.com"
              }
            ]
          },
```

And the {{keys}} smart value variable looks like this:

```
          "type": "jira.create.variable",
          "value": {
            "id": "_customsmartvalue_id_1694147937774",
            "name": {
              "type": "FREE",
              "value": "keys"
            },
            "type": "SMART",
            "query": {
              "type": "SMART",
              "value": "flavor-1,flavor-2"
            },
```

So yeah, if I were you, I'd tweak your rule to have the first couple of flavors, then Export that puppy, use the scripting/IDE/spreadsheet of your choice to generate the other mappings and list of keys, hack that into the JSON file, and Import it back in.

Whoo though, 200 different types of APIs? That doesn't sound like much fun to do manually. So yeah, you could probably do the same exercise with Web Requests, etc.

But as always, start small. Test frequently. And have fun!

comments: author: John Maner
body: Ah, split is super clever, thank you!

Also, we don't quite have 200... that's just the most which is supported by the lookup table feature ;)

Appreciate the help!