Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How can i add Web Link(like confluence link) to issue using groovy?

I have a web page URL which I want to add as Web Link to Issue(of type bug) in Jira On create

Below code not working (I am using Listener)

import com.atlassian.jira.issue.link.RemoteIssueLinkBuilder
import com.atlassian.jira.issue.link.RemoteIssueLink
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.RemoteIssueLinkManager

if(issue.getIssueTypeObject().getName()=="Bug"){
RemoteIssueLink link = new RemoteIssueLinkBuilder().issueId(issue.getId()).url("http://test.hostname.com/resource.html").title("Test-Link").build();
ComponentAccessor.getComponent(RemoteIssueLinkManager.class).createRemoteIssueLink(link, ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser());
}

1 answer

Hi @Kiranped ,

 

Your code seems to be missing the definition of issue, see the bold part before the if, and also you should use getIssueType instead of getIssueTypeObject deprecated in JIRA 7;

import com.atlassian.jira.issue.link.RemoteIssueLinkBuilder
import com.atlassian.jira.issue.link.RemoteIssueLink
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.RemoteIssueLinkManager

def issue = event.issue

if(issue.getIssueType().getName()=="Bug"){
RemoteIssueLink link = new RemoteIssueLinkBuilder().issueId(issue.getId()).url("http://test.hostname.com/resource.html").title("Test-Link").build();
ComponentAccessor.getComponent(RemoteIssueLinkManager.class).createRemoteIssueLink(link, ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser());
}

 

 Also since your listener is attached to Issue created event, you need to confirm in your workflow if the create transition is triggering the Issue created event (check for the last post-function in the create transition)

I've seen some cases that create transition was using Generic Event instead of Issue create, which didn't triggered the Listener. 

Thanks a lot, worked perfect for me (:-

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you