Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

Confluence Link working in Create but not in Clone Issue Script

Hi All,   I am using a post-function in the create step of one of my issues that generates a new confluence page and links the page.   There is a link in Jira to confluence,  and a link in confluence to Jira.   

So it works if I use the "Create" issue link from the main Jira page.  But most of the time I need to create these issues from another issue type.   So I call a post-function ->Clones and link issue.    It creates the issue,   generates the wiki page,  there is a link in the confluence page back to jira but Jira does not have a link to the confluence page.

-So I know the script works, because it works from create button

-I know the script is being called when using the "Clone and links" script because the wiki page is created. 

But I don't see how in this script it is creating the link so I am not sure how to fix it.  I have tried adding

checkLink = {link -> true};  in the additional actions section of the clone link,  but no difference.

 

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 groovy.xml.MarkupBuilder

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

// the issue provided to us in the binding
Issue issue = issue


def confluenceLink = getPrimaryConfluenceLink()
assert confluenceLink // must have a working app link set up

def authenticatedRequestFactory = confluenceLink.createImpersonatingAuthenticatedRequestFactory()

// write storage format using an XML builder
def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
xml.'ac:structured-macro'('ac:name': "jira") {
'ac:parameter'('ac:name': "key", issue.key)
'ac:parameter' ('ac:name': "server", "ES PoC JIRA")
'ac:parameter' ('ac:name': "serverId", "########")
}

// retrieve contents of "template page"
def confResponse = null

authenticatedRequestFactory
.createRequest(Request.MethodType.GET, "rest/api/content?type=page&title=fm00876_IndependentDesignReviewRecord&expand=body.storage.value")
.addHeader("Content-Type", "application/json")
.execute(
new ResponseHandler<Response>()
{
@Override
void handle(Response response) throws ResponseException {
confResponse = new JsonSlurper().parseText(response.getResponseBodyAsString())
}
})

// set the page title - this should be unique in the space or page creation will fail
def pageTitle = issue.key + " Independent Design Review"

def params = [
type : "page",
title: pageTitle,
space: [
key: "TES" // set the space key - or calculate it from the project or something
],
body : [
storage: [
value : writer.toString() + confResponse.results.body.storage.value[0],
representation: "storage"
]
]
]

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 {
if (response.statusCode != HttpURLConnection.HTTP_OK) {
throw new Exception(response.getResponseBodyAsString())
} else {
def webUrl = new JsonSlurper().parseText(response.responseBodyAsString)["_links"]["webui"]
}
}
})

 

2 answers

Hi Otoole,

 

Did you get a solution for the above problem.

 

Regards,

Parthi

No I have not found an answer

I did a workaround to add another transition to call this script to "start" an issue.  Only purpose of that transition is to run this script.

So the script operates correctly when called from "Create" step started from web page.

Script does not work when issue "Create" called from the link and clone script.

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