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

Is it possible to to create in ticket a link to a page in confluence using scriptrunner in jira post

Is it possible to to create in ticket a link to a page in confluence using scriptrunner in jira post function?

The option described in the docking is not suitable, The page is needed in the wiki.

On the confluence side, I create a ticket backlink using {jira: key = $ {issue.key}} in the pagebody. But I do not understand how to create a link of the "Confluence page" type on the jira side.

import com.atlassian.applinks.api.ApplicationLink
import com.atlassian.applinks.api.ApplicationLinkService
import com.atlassian.applinks.api.application.confluence.ConfluenceApplicationType
import com.atlassian.jira.issue.Issue
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.sal.api.net.Request
import com.atlassian.sal.api.net.Response
import com.atlassian.sal.api.net.ResponseException
import com.atlassian.sal.api.net.ResponseHandler
import groovy.json.JsonBuilder
import groovy.json.JsonSlurper

import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.link.*
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

def ApplicationLink getPrimaryConfluenceLink() {
def applicationLinkService = ComponentLocator.getComponent(ApplicationLinkService)
final ApplicationLink conflLink = applicationLinkService.getPrimaryApplicationLink(ConfluenceApplicationType)
conflLink
}

Issue Issue = issue

def confluenceLink = getPrimaryConfluenceLink()
assert confluenceLink

def authenticatedRequestFactory = confluenceLink.createImpersonatingAuthenticatedRequestFactory()

def pageTitle = issue.key + " Discussion" as String


def pageBody = """h3. ${issue.summary}

{jira: key = ${issue.key}}
{quote}${issue.description}{quote}

"""

def params = [
type : "page",
title: pageTitle,
space: [
key: "testovoe"
],

body : [
storage: [
value : pageBody,
representation: "wiki"
],
],
]

authenticatedRequestFactory
.createRequest(Request.MethodType.POST, "rest/api/content")
.addHeader("Content-Type", "application/json")
.setRequestBody(new JsonBuilder(params).toString())
.execute(new ResponseHandler<Response>() {
@Override
void handle(Response response) throws ResponseException {

def webUrl = new JsonSlurper().parseText(response.responseBodyAsString)["_links"]["webui"]
def newurl = webUrl as String

def newweb = "https://my.confluenceserver.com" + newurl -"]"-"["
log.debug newweb

}
})

 

1 answer

1 accepted

0 votes
Answer accepted

Normally, when you create a jira issue macro in a confluence page, it automatically creates a link back to the source confluence page in the jira issue as "mentioned in <pagename>". But that doesn't seem to happen automatically when creating using api this way.

Is this what you are trying to achieve?

Or are you asking how to include a link to another pre-existing page in the wiki pageBody?

If so, something like this should work:

def pageBody = """h3. ${issue.summary}

{jira: key = ${issue.key}}
{quote}${issue.description}{quote}

[Link To Page|Name of the page to link to]
"""

Hello, Peter-Dave Sheehan 

The automatic link in jira to wikipage does not work in this case and it makes me sad.

I just need to create a link on the Jira side.

I played around with this ... try to generate your pagebody jira macro with additional attributes

{jira: key=${issue.key}|serverId=xxx-xxx-xxx-xx|server=yyy}

Get the xxx-xxxx and yyy values from a macro that you insert manually. It will be the application id and name from your confluence applinks

When I specify both of those parameters, the "mention on" links is created automatically for me.

Like andrey_permyakov likes this

It worked.

Thanks!

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Trello

🏊‍♀️ Atlympic Event: Trello

Hello Community!  Quick disclaimer: We are running a contest on Community (The Atlympics!) from July 23rd - August 8th of 2021. If you are interested in participating in this contest (prizes! ...

129 views 1 12
Read article

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