Jira Automation - Linked Issue Macro ?
Asked by Matt Lind:

i write a lot of JIRA Automation rules to connect JIRA to SLACK, based on triggered events occurring in JIRA.   

I'm looking for two things:  
1. the basic macro that lists out all LINKED ISSUES.  
i've been trying to use **{{issue.issuelinks.first.inwardIssue.key}}** but that returned a blank/NULL  

2. macro for most-recent / new linked issue.   
this way i can program an initial alert for ALL LINKED ISSUES, and then a second alert if a new linked issued is linked.   

--COPY OF MY AUTOMATION JIRA TEXT WITH CURRENT MACROS--  

```
*---NEW LINKED ISSUE----* 
*JIRA:* {{issue.key}} *
Link:* <https://tihealth.atlassian.net/browse/{{issue.key}}> 

Program Status is now set to: {{issue.status.name}} 

--- 
Linked Issues: {{issue.issuelinks.first.inwardIssue.key}}? <--this doesnt work
--- 
Tag Type Setting: {{issue.fields.customfield_11182}} 
--- 
::DCM IDs:: Profile: {{issue.fields.customfield_11269}} 
SubProfile: {{issue.fields.customfield_11270}} 
Campaign: {{issue.fields.customfield_11271}} 
Partner ID: {{issue.fields.customfield_11289}} 
Auction ID report scheduled: {{issue.fields.customfield_11272}} 
-------------------------------
```


Answers:
author: Bill Sheboy
body: Hi [@Matt Lind](/t5/user/viewprofilepage/user-id/3183227) -- Welcome to the Atlassian Community!

Some issue link types are directional, and so the inwardIssue attribute will not include all of the issue links.

If you only wanted the inward links, please try this:

```
{{issue.issuelinks.inwardIssue.key}}
```

If you only wanted the outward links, please try this:

```
{{issue.issuelinks.outwardIssue.key}}
```

FYI, I recommend using this how-to article for finding all smart values, and testing with an example issue, to learn more about the structure of the smart values within an issue: <https://support.atlassian.com/cloud-automation/docs/find-the-smart-value-for-a-field/>

Kind regards,  
Bill

comments: author: Matt Lind
body: Thanks Bill,  
All my issues are linked using the "relates to" type.  
this does not appear to have an inward or outward type. for example, all the other linked-types such as "blocks" or "created" have two selections:  
- blocks  
- is blocked by  
OR  
- creates  
- is created by  
So, what would the right Macro be for Linked Issues using the "relates to" type?


author: Bill Sheboy
body: If you only want the linked issues for a specify type, your two options are:

* Use the Lookup Issues action with JQL and the linkedIssues() function, then use the lookup result in your message: <https://support.atlassian.com/jira-software-cloud/docs/jql-functions/#linkedIssues-->
* Use smart value, list filtering on the issuelinks smart value to return only the issues for that type. For the "relates to" type, the name "Relates" may be used in the filter to return the inwardIssue ones.


author: Matt Lind
body: Thanks Bill, but can JIRA automation use JQL?  

I've been using Automation macros which uses {{xxxx.xxx}} syntax.


author: Bill Sheboy
body: Yes...

The Lookup Issues action may use JQL to gather a set of issues.

To process issues individually, branching on JQL is possible.

Additionally, there are rule conditions which may use JQL.


author: Matt Lind
body: i figured out "Relates To" does have background Inward Issues vs Outward issues types, even though there is only one drop down...  

if you link Ticket B as a "relates to" linked issue while you are within ticket A, its Outward for any Automation rules pertaining to issue A, but it would be an Inward issue if writing rules pertaining to Ticket B -- and vice-versa.  

These were both relevant since users sometimes link issues on either side of Ticket A/B divide.  
And, that also means you need to write 2 automation rules if the linked issues are across Projects if (like me) your automation rule permissions limit you to a single Project at a time.

```
{{issue.issuelinks.inwardIssue.key}},{{issue.issuelinks.outwardIssue.key}}
```


author: Bill Sheboy
body: Yes, and...

In my experience, I have not found rule behavior consistent (i.e., deterministic) regarding which issue is the "trigger" versus "destination" when the trigger was Issue Linked. And when a specific link type is specified for cross-project issue linking, the rule scope also impacted behavior. Worsening this, some Jira behavior occurs in multiple steps (i.e., not one event) and so the links are added / modified after another rule may have triggered by an event. E.g., cloning with links. Although I admin it may be the behavior is deterministic, but just not documented well / unambiguously.

When the link direction matters with this trigger type, I include rule logic to handle both possible paths in a single rule, when possible :\^)


Tags: cloud

jira-cloud