Hi
I'm trying to write script to be used as post function to link the issue to a specific confluence page.
I tried this script- it didn't return any error but didn't do much either.
import com.atlassian.jira.ComponentManager import com.atlassian.jira.bc.issue.issuelink.RemoteIssueLinkService import com.atlassian.jira.bc.issue.link.RemoteIssueLinkService import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.link.RemoteIssueLinkBuilder class myWrapper { def doStuff() { def authContext = ComponentAccessor.getJiraAuthenticationContext() Issue issue = ComponentAccessor.getIssueManager().getIssueObject("TEST-111") def linkBuilder = new RemoteIssueLinkBuilder() linkBuilder.issueId(issue.getId()) linkBuilder.applicationName("Confluence- Test") linkBuilder.applicationType("com.atlassian.confluence") linkBuilder.relationship("Wiki Page") linkBuilder.title("test1") linkBuilder.url("http://conf:8090/display/TS/test1") def link = linkBuilder.build() def remoteIssueLinkService = ComponentManager.getComponentInstanceOfType(RemoteIssueLinkService.class) def validationResult = remoteIssueLinkService.validateCreate(authContext.getLoggedInUser(), link) RemoteIssueLinkService.RemoteIssueLinkListResult links = remoteIssueLinkService.getRemoteIssueLinksForIssue(authContext.getLoggedInUser(), issue) } } (new myWrapper()).doStuff()
Versions:
Jira - 7.1.0
confluence -5.8.14
Thanks!!
Dar
Community moderators have prevented the ability to post new answers.
You need to actually call remoteIssueLinkService.create() with the result from validateCreate, like this:
def remoteIssueLinkService = ComponentManager.getComponentInstanceOfType(RemoteIssueLinkService.class) def validationResult = remoteIssueLinkService.validateCreate(authContext.getLoggedInUser(), link) //new code start def createResult = remoteIssueLinkService.create(authContext.getLoggedInUser(), validationResult) //new code end RemoteIssueLinkService.RemoteIssueLinkListResult links = remoteIssueLinkService.getRemoteIssueLinksForIssue(authContext.getLoggedInUser(), issue)
Thank a lot Peter!!
works great!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Cool, I'm glad I was able to help! Please accept the answer so the question is closed.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
please some one can help me how to retrieve current issue id in above code instead of " Issue issue = ComponentAccessor.getIssueManager().getIssueObject(
"TEST-111"
)" .
I mean don't want to hard code value like "TEST-111"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
See my post above where I added the call to set the "globalId". This solved the issue for me.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, I'm trying a little different version of this code in order to create a link to a Confluence page when a subtask is created. This code is located as a post-function in the Create transition of the subtask.
import com.atlassian.jira.bc.issue.issuelink.RemoteIssueLinkService
import com.atlassian.jira.bc.issue.link.RemoteIssueLinkService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.RemoteIssueLinkBuilder
import org.apache.log4j.Category
def Category log = Category.getInstance("com.onresolve.jira.groovy.*")
log.setLevel(org.apache.log4j.Level.INFO);
def urlPage = issue.getParentObject().getKey() + ": " + issue.getParentObject().getSummary()
urlPage = urlPage.replaceAll(":", "%3A")
urlPage = urlPage.replaceAll(" ", "+")
def authContext = ComponentAccessor.getJiraAuthenticationContext()
def linkBuilder = new RemoteIssueLinkBuilder()
linkBuilder.issueId(issue.getId())
linkBuilder.applicationName("Confluence")
linkBuilder.applicationType("com.atlassian.confluence")
linkBuilder.relationship("Wiki Page")
linkBuilder.title(issue.getParentObject().getKey() + ": " + issue.getParentObject().getSummary())
linkBuilder.url("http://host:8090/display/GDLD/" + urlPage)
def link = linkBuilder.build()
log.info("ID issue: " + issue.getId())
log.info("Texto URL: " + "http://host:8090/display/GDLD/" + urlPage)
def remoteIssueLinkService = ComponentAccessor.getComponent(RemoteIssueLinkService.class)
def validationResult = remoteIssueLinkService.validateCreate(ComponentAccessor.getUserManager().getUserByName("admin"), link)
if(validationResult.isValid()){
log.info("VALIDO")
def createResult = remoteIssueLinkService.create(ComponentAccessor.getUserManager().getUserByName("admin"), validationResult)
RemoteIssueLinkService.RemoteIssueLinkListResult links = remoteIssueLinkService.getRemoteIssueLinksForIssue(ComponentAccessor.getUserManager().getUserByName("admin"), issue)
}else{
log.info("NO VALIDO")
log.info(validationResult.getErrorCollection())
}
As a result I get the link created in Jira, but it shows the Couldn't load message. In Confluence Page I can't see the link back to jira issue.
Any help??
Thanks!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Diego Rodriguez ,
I am facing similar issue like you.
Did you find out any Solutions for this issue.
Thanks
Abi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I also have this issue, while there is an error, the link still works:
Haven't solved it yet.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I do see this error in the log file, but not sure how to solve it. Maybe this is related to the 'Failed to load' message.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I solved this in my instance of 7.9.2.
All I did was add a call to set the globalId of the Confluence page:
linkBuilder.globalId("appId=61cf4472-a82a-3304-a1fc-ede103860d55&pageId=121608199")
I get the Confluence AppId from calling this API:
https://jira.americas.nwea.pvt/rest/applinks/1.0/applicationlink
I get the pageId from the page in Confluence.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.