Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to add dynamic URL containing {issue.id} in a custom field in JIRA DC?

Digvijay Singh Gehlot
Contributor
May 24, 2024

Hi All,

I want to add a dynamic URL : "https://<jira-instance>.com/secure/EditIssue!default.jspa?id={issue.id}" in a custom field.

When a user clicks on the Create button present on Create Issue screen after filling the necessary fields, the above Edit Issue link should automatically fetch the {issue.id} and the updated link should save in a custom field. 

Then user should see that dynamic hyperlink in a custom field in HTML format like "To Edit Issue, Click here".

Please guide on how we can configure it using Automation/ Post Functions/ Behaviour using scriptrunner/ JMWE?

And please provide screenshots for reference, it will be a great help to fulfil this use-case.

Thank you

2 answers

1 vote
Vikrant Yadav
Community Champion
May 24, 2024

Hi @Digvijay Singh Gehlot  After issue creation only you can get issue.key, on Create screen you can't get issue Id. 
You need to apply Post function here or use project automation. In Automation use  "Issue Created" trigger and Action >> Edt issue >> Select Field Enter string : https://<jira-instance>.com/secure/EditIssue!default.jspa?id={{issue.key}}

 

Thanks

Digvijay Singh Gehlot May 24, 2024

Hi @Vikrant Yadav 

It worked by using Automation: When: Issue created > Then: Edit issue fields > Selecting an URL custom field > And Set the dynamic url as https://<jira-instance>.com/secure/EditIssue!default.jspa?id={{issue.id}}.

Now, how can I use URL custom field in HTML format so that I can show this dynamic link as "Click here" in the custom field value?

Thank you for your assistance! 

Like Vikrant Yadav likes this
Vikrant Yadav
Community Champion
May 24, 2024

Hi @Digvijay Singh Gehlot 

In URL you can't add Wiki Markup. 

You need to use Multi-line text field in which Wiki style rendering should be enabled, then you only it works like button. 

[Wikipedia|https://www.wikipedia.org]

[link text|http://www.example.com]

Edit option available in Jira, why need to Custom field with Edit link?

 

Digvijay Singh Gehlot
Contributor
May 28, 2024

Hi @Vikrant Yadav 

I tried with Multi-line text field by enabling Wiki style rendering, but the dynamic url with {issue.id} is not displaying as "Click here" on Edit/ View Issue screen.

My use-case is,

1) I want that my Sales representatives directly see their Dashboard only when they login

2) Create issue by clicking on Create Issue Link (using direct HTML link i.e. /secure/CreateIssueDetails!init.jspa?pid=<projectid>&issuetype=<issueid>)

3) When they hit the Create button on that link, they are redirected to Dashboard again.

4) Once issue is created, they can see Edit Issue Link (dynamic url with {issue.id}) present on Dashboard, restricting them to access/ bypass the View Issue screen.

Please guide further how can I achieve this as per the given workflow or at least show them the Edit Issue (dynamic link) on the Dashboard.

Thank you

Vikrant Yadav
Community Champion
May 28, 2024

@Digvijay Singh Gehlot How is it showing on View screen ? Or field is not visible on View screen ? Is it simple text not showing as hyperlink ?

0 votes
Matt Parks
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 24, 2024

We've done something similar as a Scriptrunner fragment. It's a button that, when selected, copies the Issue Key and summary as an HTML link that redirects back to the issue. Below is the code for the button. You'll need to modify it slightly, but this should probably get you what you're looking for.

The makeXMLFriendly function at the bottom is to replace restricted characters from the Summary with their HTML equivalent. If you're just looking for the link, you wouldn't need to worry about that, since you're not including the Summary as the name of your link.

 

def baseurl = com.atlassian.jira.component.ComponentAccessor.getApplicationProperties().getString("jira.baseurl")

def summary = makeXmlFriendly(context.issue.summary);
writer.write("""<span id="copyText" style="visibility:hidden"></span>
<button onclick="copyToClipboard()">Copy to Clipboard</button>

<script>
function copyToClipboard()
{
  var copyText = document.getElementById("copyText");
  copyText.style.visibility = "visible"
 
  copyText.innerHTML = "<a href='${baseurl}/browse/${context.issue.key}'>${context.issue.key} - ${summary}</a>"
 
  var r = document.createRange();
    r.selectNode(copyText);
    window.getSelection().removeAllRanges();
    window.getSelection().addRange(r);
    document.execCommand('copy');
    window.getSelection().removeAllRanges();
 
  copyText.innerHTML=""
}
</script>""");


private String makeXmlFriendly(String xml)
{
    xml = replaceIfFound(xml, '<', "&lt;");
    xml = replaceIfFound(xml, '>', "&gt;");
    xml = replaceIfFound(xml, '&', "&amp;");
    xml = replaceIfFound(xml, '"', "&quot;");
    return xml;
}


private String replaceIfFound(String xml, String find, String replace)
{
    if (!xml.contains(find))
    {
        return xml;
    }
   
    xml = xml.replace(find, replace)
    return xml;
}

Suggest an answer

Log in or Sign up to answer