Automation to find oldest linked ticket
Asked by Terry Dance:

I have a process for problem tickets.

Problem stores the date of the oldest linked ticket created date in a field.

When you link a new incident, it checks the created date of that ticket, against the stored date. If the newly linked ticket is "older", then that stored date is replaced by the date in the newly linked ticket. I then have automations that do calculations after that.

What I am stuck on, is if you de-link a ticket, then check the linked tickets for the now "oldest" date and set that as the stored field in the Problem ticket.


Answers:
author: Trudy Claspill
body: Hello [@Terry Dance](/t5/user/viewprofilepage/user-id/5385711)

You can use the Lookup Issues action to execute a JQL to find the tickets linked to the target ticket. Set the JQL to order by Created ASC. That will put the oldest ticket first in the results set.

To access information in that first item use

{{lookupIssues.first.*fieldName*}}

In that manner you can get the created timestamp of the oldest linked ticket.

comments: author: Terry Dance
body: What value would I put in the for issue key? The smart value isnt working.


author: Trudy Claspill
body: Please provide a screen image showing your complete rule. I can't tell you why it isn't working without that information.

This is an example of such a rule.

![Screenshot 2024-08-28 at 10.54.33?AM.png](https://community.atlassian.com/t5/image/serverpage/image-id/344316i8401E8F9E9BCB245/image-size/large?v=v2&px=999 "Screenshot 2024-08-28 at 10.54.33?AM.png")

**HOWEVER** links are considered directional. When you remove a link two issues are affected. This rule will not necessarily be triggered by the issue you are viewing when you remove the link. It will be triggered by the issue that is considered the "source" in the link relationship.

Link Types have an Inward and Outward Description. For example:

|----------------|--------------------|---------------------|
| link type name | Inward Description | Outward Description |
| Blocks         | is blocked by      | blocks              |

If the link between two issues is:

ABC-1 blocks ABC-2

ABC-2 is blocked by ABC-1

...then ABC-1 is considered the "source". When viewing ABC-1 you would see "blocks" (the Outward Description) in the Issue Links section, describing its relationship to ABC-2.

So, if you were viewing ABC-2 and removed the link to ABC-1, the rule would actually be triggered for ABC-1.


author: Terry Dance
body: Its all good I used the lookupissues action and ordered them to have the oldest ticket first. I then clear the field that was storing the date of the oldest linked ticket, then input the created date of whatever the now oldest ticket is. Which then kicks off my calculations. So it now works for linking and unlinking.


author: Walter Buggenhout
body: Hi [@Terry Dance](/t5/user/viewprofilepage/user-id/5385711),

From your description, it seems as if you already have all in place to go through the issues, lookup the oldest date and update your issue. So I assume your biggest problem is finding the issue that is no longer linked?

There is an automation trigger *issue link deleted* that you can use to identify the issues on both ends of the removed link. The following smart values identify those issues:

```
{{issue.key}}
{{destinationIssue.key}}
```

If you have those, I would assume you could fill the gap in your logic to kick off the calculations you are already able to perform.

Hope this helps!

comments: author: Terry Dance
body: Im just using a Issue Linked trigger, and comparing its createddate to the stored date I have on the automation.


Tags: cloud

jira-service-management

jira-service-management-cloud