Getting the parent issue key in automation
Asked by Jamshaid:

I have two projects TM and CO. When in TM, an issue is created, same issue is cloned to CO and a Cloners link is created between both issues.

What I want to do is that when the issue in CO is transitioned to **Done,**it should send a web request having the key of parent issue in TM project in its parameters or body. I am unable to get the link between both issues. Here is what I have tried

![123.png](https://community.atlassian.com/t5/image/serverpage/image-id/306006iC3E9D573AB77D25D/image-size/large?v=v2&px=999 "123.png")

But, this condition never triggered. It always ends up with this response

![1234.png](https://community.atlassian.com/t5/image/serverpage/image-id/306008iCFD5EF769B127051/image-size/large?v=v2&px=999 "1234.png")

I am unable to get what I should do regarding this as I am totally new to automation in Jira.

Thanks


Answers:
author: Jamshaid
body: I had to transition the linked issue to **Done**state and send a web request containing the parent issue key. Here is how I did it. I created a shared rule between both projects and then used the following automation flow to close the issue and send web request.

![Screenshot from 2024-02-26 21-34-45.png](https://community.atlassian.com/t5/image/serverpage/image-id/308699iEBE1E7B7976DF6F0/image-size/large?v=v2&px=999 "Screenshot from 2024-02-26 21-34-45.png")


author: Kalyan Sattaluri
body: [@Jamshaid](/t5/user/viewprofilepage/user-id/4092272) Is your TM project available in scope from the rule of CO project?

I just tested a similar set up and if the cloned issue is within the same project, branch logic like you have picks it up as expected but if you dont have "scope" then you wont get the key from TM project.

So if thats the case with you and that is why you are not able to get the key, I was thinking of below approach which is without the branch logic.

But please confirm above step as thats the easiest route or work with your admin if you can be granted that scope.

*** ** * ** ***

My proposal was, Before your branch, first please try to log below smart value, should pull the list of keys.. modify the if condition accordingly.  
{{#issue.issuelinks}}{{#if(equals(type.name,"Cloners"))}}{{inwardIssue.key}}{{\^last}}, {{/}}{{/}}{{/}}  
You then convert this into a list by first storing above smart value into a variable (myvar) and doing a split. {{myvar.split(", ")}}, now you have a list of keys.  
If you want to loop through and make a web request call for each of "parent" /original cloned link, I believe you can do an "advanced branch" afterwards on {{myvar.split(", ")}} and make your web request calls for each "key" that way. Something along the lines of below thread or similar posts which loop over a list.  
<https://community.atlassian.com/t5/Jira-Service-Management/Automation-loop-through-WebResponse-results/qaq-p/2140920>  
hope it helps. If this is not what you are thinking of, please help explain what do you want to do.

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/306258i399A9818D23F86B5/image-size/large?v=v2&px=999 "image.png")

comments: author: Jamshaid
body: [@Kalyan Sattaluri](/t5/user/viewprofilepage/user-id/5312306) Thanks. I am not really concerned about using branch logic. I just want to get the key of the parent issue. It is supposed to be only one having the current logic.   
I will try your solution.


author: Kalyan Sattaluri
body: [@Jamshaid](/t5/user/viewprofilepage/user-id/4092272) Sure, Just edited my post with screenshot, please check and let me know


author: Jamshaid
body: [@Kalyan Sattaluri](/t5/user/viewprofilepage/user-id/5312306) I can't find **Add value to Audit Log** in **then: Add an action**


author: Kalyan Sattaluri
body: In cloud, its called "Log action", please verify.

BTW, if you know you will only have 1 ofsuch cloned issue, you can skip variable part.

Either way, please log value first to check you are getting the value.

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/306259iAEC665093908C32C/image-size/large?v=v2&px=999 "image.png")


author: Jamshaid
body: [@Kalyan Sattaluri](/t5/user/viewprofilepage/user-id/5312306)

Here is what appears in logs. It does not print anything from issue

![logs.png](https://community.atlassian.com/t5/image/serverpage/image-id/306264i5D91F313AFFDBB4F/image-size/large?v=v2&px=999 "logs.png")

Here is my rule

![111.png](https://community.atlassian.com/t5/image/serverpage/image-id/306261i24DCDD71B52E5C99/image-size/large?v=v2&px=999 "111.png")

Here is the issue CO18

![co18.png](https://community.atlassian.com/t5/image/serverpage/image-id/306262i808EF32D7257DBBD/image-size/large?v=v2&px=999 "co18.png")


author: Kalyan Sattaluri
body: Your log below has TM-63 and your screenshot has TM-67.

Please post similar log like you posted below so we can cross check that it should be "inwards" or outwards direction in our log action


author: Jamshaid
body: [@Kalyan Sattaluri](/t5/user/viewprofilepage/user-id/5312306) I have got the list of linked issues. Thanks for your help

**{{issue.links}}** worked for me. It is enough for now.


author: Jamshaid
body: [@Kalyan Sattaluri](/t5/user/viewprofilepage/user-id/5312306) The json shows that it is an inward

```
 "issuelinks": [
{
"id": "10656",
"self": "https://mysite.atlassian.net/rest/api/2/issueLink/10656",
"type": {
"id": "10001",
"name": "Cloners",
"inward": "is cloned by",
"outward": "clones",
"self": "https://mysite.atlassian.net/rest/api/2/issueLinkType/10001"
},
"inwardIssue": {
"id": "11214",
"key": "TM-63",
"self": "https://mysite.atlassian.net/rest/api/2/issue/11214",
"fields": {
"summary": "test211",
"status": {
"self": "https://mysite.atlassian.net/rest/api/2/status/10001",
"description": "",
"iconUrl": "https://mysite.atlassian.net/images/icons/status_generic.gif",
"name": "Done",
"id": "10001",
"statusCategory": {
"self": "https://mysite.atlassian.net/rest/api/2/statuscategory/3",
"id": 3,
"key": "done",
"colorName": "green",
"name": "Done"
}. ?
```

I don't know why the condition you shared is not working


author: Kalyan Sattaluri
body: Great, but the JSON you are showing again is for TM-63 and your screenshot has TM-67. I am curious whats the difference in link types between the two because syntax worked for me. Thats why I asked for JSON which showed TM-67 to look at the difference.

Either way, looks like you got what you wanted. Problem solved!


author: Jamshaid
body: [@Kalyan Sattaluri](/t5/user/viewprofilepage/user-id/5312306) that json was for another issue. I just copied it from my other comments in this post.

I have linked another issue and it shows a comma (,) only in logs while trying your condition. Maybe something got changed by the webpage when you pasted the condition?


author: Jamshaid
body: [@Kalyan Sattaluri](/t5/user/viewprofilepage/user-id/5312306) The condition works with outwardIssue.key

**{{#issue.issuelinks}}{{#if(equals(type.name,"Cloners"))}}{{outwardIssue.key}}{{\^last}}, {{/}}{{/}}{{/}}**


author: Kalyan Sattaluri
body: [@Jamshaid](/t5/user/viewprofilepage/user-id/4092272) if you have figured out a way, please consider to put it in a new post and mark your answer as accepted so others can benefit and that way this issue is closed.


author: Rudy Holtkamp
body: Hi [@Jamshaid](/t5/user/viewprofilepage/user-id/4092272) ,

Maybe you should use 'cloned by' instead of 'clones' in the branch.

It depends how the two issues are linked.

comments: author: Jamshaid
body: [@Rudy Holtkamp](/t5/user/viewprofilepage/user-id/636802) Even if i use **is cloned by,**it throws the same message in logs


author: Rudy Holtkamp
body: The log says that it can't find a linked issue of the link type 'clones'.

So you might want to take a closer look to the issue by using:

<https://yoursite.atlassian.net/rest/api/latest/issue/CO-17?expand=names>

Then search for 'issuelinks', you should see something like this:

```
"issuelinks": [
  {
    "id": "10762",
    "self": "https://rudy.atlassian.net/rest/api/2/issueLink/10762",
    "type": {
      "id": "10001",
      "name": "Cloners",
      "inward": "is cloned by",
      "outward": "clones",
      "self": "https://rudy.atlassian.net/rest/api/2/issueLinkType/10001"
    },
    "outwardIssue": {
      "id": "11999",
      "key": "RUDY-15",
      "self": "https://rudy.atlassian.net/rest/api/2/issue/11999",
      "fields": {}
    }
  }
]
```

Note: I use Chrome with an extension called JSON formatter.


author: Jamshaid
body: [@Rudy Holtkamp](/t5/user/viewprofilepage/user-id/636802) this is the relevant output

```
 "issuelinks": [
{
"id": "10656",
"self": "https://mysite.atlassian.net/rest/api/2/issueLink/10656",
"type": {
"id": "10001",
"name": "Cloners",
"inward": "is cloned by",
"outward": "clones",
"self": "https://mysite.atlassian.net/rest/api/2/issueLinkType/10001"
},
"inwardIssue": {
"id": "11214",
"key": "TM-63",
"self": "https://mysite.atlassian.net/rest/api/2/issue/11214",
"fields": {
"summary": "test211",
"status": {
"self": "https://mysite.atlassian.net/rest/api/2/status/10001",
"description": "",
"iconUrl": "https://mysite.atlassian.net/images/icons/status_generic.gif",
"name": "Done",
"id": "10001",
"statusCategory": {
"self": "https://mysite.atlassian.net/rest/api/2/statuscategory/3",
"id": 3,
"key": "done",
"colorName": "green",
"name": "Done"
}
},
"priority": {
"self": "https://mysite.atlassian.net/rest/api/2/priority/3",
"iconUrl": "https://luminsec.atlassian.net/images/icons/priorities/medium.svg",
"name": "Medium",
"id": "3"
},
"issuetype": {
"self": "https://mysite.atlassian.net/rest/api/2/issuetype/10101",
"id": "10101",
"description": "A problem which impairs or prevents the functions of the product.",
"iconUrl": "https://mysite.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10303?size=medium",
"name": "Bug",
"subtask": false,
"avatarId": 10303,
"hierarchyLevel": 0
}
}
}
}
],
```