Can I retrieve the issue key of a Linked Issue in Automation for JIRA?

Paul_Sorauer February 14, 2019

Hi there

Using Automation For JIRA, when a parent issue has some action performed (transition, edit, etc), I'd like to branch to sub-tasks and create a linked issue on each sub-task to an issue already linked on the parent (there should be only one of a particular type of issue link on the parent).

Is there a way I can use a Smart Value to achieve this?

Cheers,

Paul

2 answers

1 accepted

5 votes
Answer accepted
Brydie McCoy (CB)
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.
February 17, 2019

Hi Paul,

I think the answer is 'it depends'.  You can access any values in the json response for getting an issue i.e. http://<my-instance>/rest/api/2/issue/<my-issue-key> issue links are included in this data.  We do provide a few different functions for dealing with lists of data as documented here.  The problem is figuring out which link to use, we don't really provide a way to search through the links.  So if you know it will always be the first link, or the last you could use something like:

{{issue.issuelinks.first.outwardIssue.key}}
or
{{issue.issuelinks.first.inwardIssue.key}}

Of if its the only inward or outward then you could just use: 

{{issue.issuelinks.inwardIssue.key}}

Which loops over all issue links and spits out all the keys, it ignores objects that don't have the inwardIssue property.

Hope that helps,
Brydie [Automation for Jira]

Paul_Sorauer February 17, 2019

Hi @Brydie McCoy (CB) 

Thanks for your answer.

So if I understand it correctly, you can iterate over the list but there's no way to find a particular link type, e.g. find the "has a new parent (as part of move to future sprint) of" linked issue (assuming that there are multiple outward issues but only one of that type of issue link), in the following:

"issuelinks": [
{
"id": "10951",
"self": "https://XXXXXXXXXXXXXXX.atlassian.net/rest/api/2/issueLink/10951",
"type": {
"id": "10300",
"name": "New Lineage",
"inward": "is the new parent (as part of move to future sprint) of",
"outward": "has a new parent (as part of move to future sprint) of",
"self": "https://XXXXXXXXXXXXXXX.atlassian.net/rest/api/2/issueLinkType/10300"
},
"outwardIssue": {
"id": "10506",
"key": "DOSUP-9",
"self": "https://XXXXXXXXXXXXXXX.atlassian.net/rest/api/2/issue/10506",
"fields": {
"summary": "DevOps Support - Sprint 8",
"status": {
"self": "https://XXXXXXXXXXXXXXX.atlassian.net/rest/api/2/status/6",
"description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.",
"iconUrl": "https://XXXXXXXXXXXXXXX.atlassian.net/images/icons/statuses/closed.png",
"name": "Closed",
"id": "6",
"statusCategory": {
"self": "https://XXXXXXXXXXXXXXX.atlassian.net/rest/api/2/statuscategory/3",
"id": 3,
"key": "done",
"colorName": "green",
"name": "Done"
}
},
...

 

Thanks,

Paul

Brydie McCoy (CB)
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.
February 18, 2019

HI Paul,

Yes that is correct.  We do have a ticket to be able to filter list values: AUT-1241

However, it might be a while before we get to it.

Cheers,
Brydie 

Paul_Sorauer February 18, 2019

Thanks @Brydie McCoy (CB) 

0 votes
Paul_Sorauer February 24, 2019

FYI - in our context I have figured out a workaround...

Our use case dictates that logically there should only ever be one linked issue with the particular issue type we're looking for. Therefore we can build a pretty simple trigger to capture when a new linked issue occurs and save the key to a custom field which can then be used in later triggers.

Of course if you need to support multiple values you could probably roll your own version of storing comma-separated values in a custom field, though whether it's for one or many values, there's no trigger from AFJ for unlink issue, so hard to know how to remove keys from the custom field. In our case though we don't need it. If you did you could implement it via the ScriptRunner add-in. (Without AFJ supporting scripts, coupling it with an add-on that allows you to run scripts for your more advanced workflows is probably the best way forward).

Hope that might help someone.

 

Cheers,

Paul

Dave Furlani April 16, 2019

Can you share a code sample please, Paul?

Paul_Sorauer April 25, 2019

@Dave Furlani Ours is a pretty specific scenario... As per this thread, AFJ can't provide an actual issue key via SmartTag, so we simply created a custom field and have business logic to add the issue key to that custom field as per our requirements. So now, instead of using a Smart Tag to retrieve the issue, we can use the field. Make sense? It's not really practical to share a code sample - we're using ScriptRunner - but you ought to be able to use AFJ to build up an appropriate business rules function(s) to save the correct issue key to a custom field.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events