Create automatic linked issues when writing an ticket number in description field

Owen Schikhof April 28, 2022

Hi, 

I need an automation to created linked issues to an existing issues which is mentioned in the description field.

Case: Users write one or more JIRA ticket IDs in the description field of a (new) ticket. I'd like to automatically link the newly created issue with the mentioned ones from the description field (create an issue link).

I tried to make my own variant of the "Link issues that are mentioned in the comments" rule that is available in the library of Jira.
I just don't know how to get this working from the description field instead of the comment field.

 

Any ideas?

2 answers

0 votes
Wilmer Medina _ServiceRocket_
Contributor
November 24, 2023

Hi @Owen Schikhof 

Wilmer here, PM @ ServiceRocket

We recently launched a solution that might help you!

Take a look at our marketplace listing here: Automatic Issue Links for Jira

It's in Beta, and we will be adding new features shortly, like adding links from issues in the description.

 

Let me know if it works for you! We would like to know your thoughts.

 

Cheers

Wilmer M.

0 votes
Bill Sheboy
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.
April 28, 2022

Hi @Owen Schikhof 

Please try writing the description of an issue with such mentions to the automation audit log in a rule, and you will see how the text and list functions could parse the results.

For example, a description may contain something like this when written to the log:

here is some text, followed by a link to an issue: 
[myJiraUrl/browse/myIssueKey|myJiraUrl/browse/myIssueKey|smart-link]

and here is a link to another issue
[myJiraUrl/browse/myOtherIssueKey|myJiraUrl/browse/myOtherIssueKey|smart-link]

followed by some other text

Then subject to what else is stored in your description this could be parsed to produce a list of keys for the mentioned issues:

{{issue.description.split("smart-link]").match(".*browse\/(.*)").substringBefore("|")}}

To add the actual links you would use advanced edit with JSON or advanced branching on the list.

Kind regards,
Bill

Owen Schikhof April 29, 2022

Hi Bill, 

I hoped that the use of {{comment.body.match(“([A-Z]+-\d+)”)}} could be used but then with another variable. Apparantly that was not as easy as I thought it was, since I am kinda new to this :-)

I will try your suggestions above and get back to if it got me further.
Thanks so far!

Owen

Owen Schikhof April 29, 2022

Hmm I think my knowledge within automation is a bit too limited to find my way within the screens and options...

Bill Sheboy
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.
April 29, 2022

Owen, would you please post images of your rule and the audit log details, and what is not working as you expect?  That may help the community give more focus to help.  Thanks!

Owen Schikhof May 4, 2022

I had in mind to make it like this, but then just try to replace the comment values with values from the description. Eventually this wasn't really working as I had no idea which values to check:

Screenshot 2022-05-04 at 10.30.17.png

 

but this is of course nothing but an ugly copy with some (probably dumb) assumptions based on the comment rule that created link issues on smart objects.

Later I also thought, that you don't want existing links to be made double. 
For example, you edit the description again (for example) add another smart link), then you don't want all already existing smart links from the description which are already linked issues (related) to be linked again. That could create a lot of double linked issues hehe...not sure if Jira is taking care of this part themselves to prevent this?

And this is what I tried to make of it after you wrote me the info above. But I have the feeling that I didn't really get it..
The audit log also says I made mistakes hehe

Screenshot 2022-05-04 at 10.26.49.png

before adding the issue summery the audit log already didn't like the second part:

Failed to get value for issue.description.match("([A-Z]+-\d+)": {{issue.description.match("([A-Z]+-\d+)"}}

Of course the summary field in here makes absolutely no sense when checking on a description change..but I forgot to remove it before making the screenshot. so forget those summary fields in the issue...then you still the get the error mentioned in the audit log.

I am totally lost....sorry

Bill Sheboy
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.
May 4, 2022

Hi, Owen!

There appears to be a typo in your expression: a missing parenthesis to close the match() so perhaps that is the problem causing the error:

{{issue.description.match("([A-Z]+-\d+)")}}

I noted earlier that I do not know if that other post's regular expression works,  so I suggested the other technique with split() and match().  We really only know what works by experimentation as the documentation says their regular expressions are "based upon Java's Pattern class".  Please try writing to the audit log as you create rules to see if what you expect is happening.

 

Next, match() does this: "Performs a regular expression search and returns the first (and only one) matching regular expression group."

I interpret that as: if you believe you have multiple values, you need some way to divide your text before trying match()...such as with split() into lines.

So perhaps try this using that regular expression to split on lines and to remove any duplicates add distinct:

{{issue.description.split("\n").match("([A-Z]+-\d+)").distinct}}

 

__Bill

Owen Schikhof May 4, 2022

Hi Bill, 

I fixed the expression, indeed ) was missing...
The audit log doesn't show any updates since then.
I have applied the rule to a test project only but when creating or editing the description of an issue, no new additions to the log are added.

I now do see some errors in the log, when applying your example with distinct:

Automation-Jira.jpeg

 

The audit log now says:
Screenshot 2022-05-04 at 17.59.44.png

I hope you have an idea what this last issues is.
In our permission scheme the "single user" Automation For Jira has all the permissions. So I am not really sure what we are doing wrong here.

Owen Schikhof May 4, 2022

Addition, I have checked our security levels since we put all tickets on certain security levels. The project role "atlassian-addons-project-access" already had access to all levels. I also added the automation for jira user just to be sure...

Error is still the same...so it seems the rule is going to work when I get to solve this permission problem.... 

 

#Edit: checked all permissions, they are set properly, so perhaps there is still a small mistake in not recognising the issue numbers properly causing the error to be that the issue can't be found.

Bill Sheboy
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.
May 4, 2022

Please try writing that smart value expression to the audit log prior to the link action.  That may indicate if it contains what is expected, or if there are any stray characters.  For example:

START{{issue.description.split("\n").match("([A-Z]+-\d+)").distinct}}END

Will show if that contains only an issue key between the START and END text.

Owen Schikhof May 5, 2022

Still an error which is not getting to help me further:

 

Screenshot 2022-05-05 at 13.21.02.png

It doesn't really make clear to me if that split function is working properly.
The description only contains 1 issuenumber as a smart link. 
Wanted to try it with 1 link first before putting more in..

Owen Schikhof May 5, 2022

When I put 3 smart links in, with a tekst somewhere, the detection of the tickets seems to be ok....but the error keeps being the same about permissions or not existing. Screenshot 2022-05-05 at 13.29.17.png

 

I am confident all permissions are as they should be, so it must be something with recognising the smart links as valid issue numbers.

Bill Sheboy
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.
May 5, 2022

Hey, Owen. 

I tested and that solution from the other post does not work for me with that regular expression.  However I have re-confirmed what I first suggested works, with 1-to-many actual links from the description field:

{{issue.description.split("smart-link]").match(".*browse\/(.*)").substringBefore("|")}}

Next let's confirm: Are you putting links or text in the Description field?  Specifically, does the link show the issue type, key, summary, and status after entry?

If they are links, the above value works to link...just paste that in the Link Issues action, it will appear below the field, and you may then select it.

What this will not solve/prevent:

  • Duplicate links of different types.  If you link two issues as "block" and later this rule adds "relates to" there will be multiple links between the issues.
  • Remove links if you later remove them from the description

 

If instead you are somehow entering plain text, you may need to develop a new regular expression to parse out the values for linking.

 

Thanks,
Bill

Owen Schikhof May 6, 2022

Hi Bill,

This is an example of how our tickets are setup:

Screenshot 2022-05-06 at 12.22.58.png

I striked through some info that might be too private ;-)

gr. Owen

Bill Sheboy
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.
May 6, 2022

Yup, that will work with the syntax I provided to parse by smart-link.  I just tried it with and without bullets to confirm it identifies the keys and adds the links.

Owen Schikhof May 9, 2022

Hi Bill,

So the fact that it doesn't work here means that I do have issues with the security levels and not with the expression. That's good news and bad news.
Bad news because it's pretty hard to determine what restrictions are blocking my problem.

Though cookie....but thanks for all the help so far :-)

Owen

Owen Schikhof May 9, 2022

Hmm I think I will contact Atlassian Cloud Support for the permission issues.
I have removed alle security permission settings for issues on my test project, simplified the permission scheme of my test project and still having the same errors... snif :-(

How disappointing that I just can't find the problem...

Bill Sheboy
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.
May 9, 2022

I agree it may be time to ping Atlassian Support.  They have access to logs users cannot see and so may notice something we are missing.

When you hear back from them, please post what you learn so the community can benefit.  Thanks!

Owen Schikhof June 10, 2022

It took quite a while to get response from Atlassian Support.
They said... it's a bug within Cloud, we are looking into it.

So now it's a matter of waiting and hoping they can fix it.

Owen Schikhof June 10, 2022

I got a piece of JSON code from Atlassian which I could test and it worked.
I am not sure of I can just post that JSON code here or if that contains information that should not be published

Bill Sheboy
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.
June 10, 2022

Thanks for the follow-up, Owen!

If you can strip out/obfuscate any private stuff in the JSON and post it, I would be interested to see what worked for you.  I am unclear how permissions could cause this symptom, and why it worked for me and not for you with Jira Cloud.

If instead there is some do-not-tell-people-about-this-secret-syntax from Atlassian Support's answer, I recommend watching that rule closely as it may stop working in the future as the automation engine/REST API improves.

Kind regards,
Bill

Owen Schikhof June 13, 2022

Hi Bill,

 

This was the JSON I received from Atlassian:

{"cloud":true,"rules":[{"id":6614615,"clientKey":"XXXXXX--STRIPPED-OUT-XXXXXX","name":"Link description mentioned issues as related issues","state":"ENABLED","description":null,"authorAccountId":"XXXXXX--STRIPPED-OUT-XXXXXX","actor":{"type":"ACCOUNT_ID","value":"XXXXXX--STRIPPED-OUT-XXXXXX"},"created":1654858421955,"updated":1654858502693,"trigger":{"id":"123882944","component":"TRIGGER","parentId":null,"conditionParentId":null,"schemaVersion":2,"type":"jira.issue.field.changed","value":{"changeType":"ANY_CHANGE","fields":[{"value":"description","type":"field"}],"actions":[]},"children":[],"conditions":[],"connectionId":null},"components":[{"id":"123882945","component":"CONDITION","parentId":null,"conditionParentId":null,"schemaVersion":1,"type":"jira.comparator.condition","value":{"first":"{{issue.description}}","second":"[A-Z]+-\\d+","operator":"REGEX_CONTAINS"},"children":[],"conditions":[],"connectionId":null},{"id":"123882946","component":"ACTION","parentId":null,"conditionParentId":null,"schemaVersion":2,"type":"jira.issue.link","value":{"linkType":"inward:10003","issue":{"type":"SMART","value":"{{issue.description.match(\"([A-Z]+-\\d+)\").first}}"}},"children":[],"conditions":[],"connectionId":null}],"canOtherRuleTrigger":false,"notifyOnError":"FIRSTERROR","projects":[{"projectId":"10000","projectTypeKey":"software"}],"labels":[],"tags":[{"id":6143312,"tagType":"SAMPLE_RULE","tagValue":"global"}],"ruleScope":{"resources":["ari:cloud:jira:43b3759c-e11d-407c-977c-0259bfe6bb23:project/10000"]},"writeAccessType":"UNRESTRICTED","collaborators":[]}]}

 

What I did change in this code is replacing "first" with "distinct" from your example to make it work to pick up multiple issue numbers. Their example only took the first.

So {{issue.description.match(\"([A-Z]+-\\d+)\").first}} has become {{issue.description.match(\"([A-Z]+-\\d+)\").distinct}}

But now it's all working.

 

gr. Owen

Bill Sheboy
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.
June 13, 2022

Thanks, Owen.  That is puzzling to me why distinct would work as that could potentially return multiple values while first can only return one.

I am glad to learn you have it working...regardless of my confusion  :^)

Nikita Rao October 18, 2022

@Bill Sheboy  I am also trying to get this to work but I don't have an option to add smart value in the "Action" part of the rule. It only gives me options to link to trigger issue or most recently created issue. Any suggestions? 

Bill Sheboy
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.
October 18, 2022

Hi @Nikita Rao 

For many of the automation actions which offer a drop-down list, you can also use a smart value expression.  Which action are you trying to use?

The "trick" to make this work is:

  • in the field, type in (or paste in) your smart value...
  • and it will appear below the field
  • select it below the field
  • and it will then be used

If that does not help, please post images of your complete rule and of the audit log details showing the rule execution.  Those may provide context to explain what you are observing.  Thanks!

Kind regards,
Bill

Suggest an answer

Log in or Sign up to answer