getting error while creating confluence page from post function in jira

Sushma September 24, 2019

Hi Support,

I have a script which creates a page in confluence from jira ,page is creating successfully .but the created is not linked back in jira.

I mean in jira it is not showing the created page inside the "metioned in" Issuelink.

In post function I am getting the below error :

2019-09-24 17:41:25,015 ERROR [runner.ScriptFieldPreviewRunner]: ************************************************************************************* 2019-09-24 17:41:25,015 ERROR [runner.ScriptFieldPreviewRunner]: Script field preview failed for field that has not yet been created java.lang.IllegalArgumentException: Text must not be null or empty at Script333$1.handle(Script333.groovy:128) at com.atlassian.applinks.oauth.auth.OAuthResponseHandler.handle(OAuthResponseHandler.java:44) at com.atlassian.plugins.rest.module.jersey.JerseyRequest$1.handle(JerseyRequest.java:115) at com.atlassian.plugins.rest.module.jersey.JerseyRequest$1.handle(JerseyRequest.java:113) at com.atlassian.plugins.rest.module.jersey.JerseyRequest$2.handle(JerseyRequest.java:134) at com.atlassian.sal.core.net.HttpClientRequest.executeAndReturn(HttpClientRequest.java:104) at com.atlassian.plugins.rest.module.jersey.JerseyRequest.executeAndReturn(JerseyRequest.java:131) at com.atlassian.plugins.rest.module.jersey.JerseyRequest.execute(JerseyRequest.java:113) at com.atlassian.applinks.core.auth.ApplicationLinkRequestAdaptor.execute(ApplicationLinkRequestAdaptor.java:47) at com.atlassian.applinks.oauth.auth.OAuthRequest.execute(OAuthRequest.java:71) at com.atlassian.sal.api.net.Request$execute$1.call(Unknown Source) at Script333.run(Script333.groovy:121) 

3 answers

1 accepted

1 vote
Answer accepted
fran garcia gomera
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.
September 26, 2019

you are using a custom REST point created with scriptrunner (/rest/scriptrunner/latest/custom/createpagefromtitle), right?

not knowing that code i can't know what does that REST point do. That could be the place to addthe link creation

or, if you can retrieve the confluence page after its creation maybe you could create the link in that moment.

To do that, the code is something like this:

IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager();
issueLinkManager.createIssueLink(issue.getId(), confluenceObjectId , 10400, 1, user)

where confluenceObjectId should be either the url of the created page or the Id of that object (i don't know) and 10400 is the code of the link type

this is the table:

10000Blocksis blocked byblocks 
10001Clonersis cloned byclones 
10002Duplicateis duplicated byduplicates 
10003Relatesrelates torelates to 
10100jira_subtask_linkjira_subtask_inwardjira_subtask_outwardjira_subtask
10200Epic-Story Linkhas Epicis Epic ofjira_gh_epic_story
10300Gantt End to Starthas to be done afterhas to be done before 
10301Gantt Start to Starthas to be started together withhas to be started together with 
10302Gantt End to Endhas to be finished together withhas to be finished together with 
10303Gantt Start to Endstart is earliest end ofearliest end is start of 
10400ComplementsIs complemented byComplements 
10500Problem/Incidentis caused bycausesservicedesk_automation_default_linktype
     

sorry i can't help more

Sushma September 26, 2019

Hi @fran garcia gomera 

Thanks for the replay.

Regards

Sushma

0 votes
Najjar _Innovura_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
June 14, 2020

Hi Sushma,

We launched a new app that allows you to create pages from templates through Jira Workflow post-function and store the Confluence page in a Jira customfield to apply more actions like:

Workflow postfuntions

  • Update page permissions
  • Update page content
  • Update page title

Workflow conditions

  • Check if page was modified after a certain status transition
  • Check if page still has a placeholder

And so much more.

Please give it a try, I believe it would streamline alot of repeated effort on your team

Jira Confluence Workflow Extensions (JCWE) 

Give it a try I am confident you'll love it.

If you have any inquires or requests please drop me an email at admin@innovura.io

0 votes
fran garcia gomera
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.
September 24, 2019

@Sushma 

Share the script code, pal

Sushma September 24, 2019

import com.atlassian.applinks.api.ApplicationLink
import com.atlassian.applinks.api.ApplicationLinkService
import com.atlassian.applinks.api.application.confluence.ConfluenceApplicationType
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
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.search.SearchProvider
import groovy.xml.MarkupBuilder

def ApplicationLink getPrimaryConfluenceLink() {
def applicationLinkService = ComponentLocator.getComponent(ApplicationLinkService.class)
final ApplicationLink conflLink = applicationLinkService.getPrimaryApplicationLink(ConfluenceApplicationType.class)
conflLink
}
HashSet<String> typecomponentset = new HashSet();
HashSet<String> typeflowset = new HashSet();
def confluenceLink = getPrimaryConfluenceLink()
def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
def writer1 = new StringWriter()
def xml1 = new MarkupBuilder(writer1)
assert confluenceLink
CustomFieldManager customFieldManager = ComponentAccessor.customFieldManager
def issueManager = ComponentAccessor.getIssueManager()
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def searchService = ComponentAccessor.getComponent(SearchService)
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
HashSet batchset = new HashSet();
HashSet interfaceset = new HashSet();
def impcomponent = customFieldManager.getCustomFieldObjectByName("Impacted Technical Components")
def impcomponentvalues = issue.getCustomFieldValue(impcomponent)
log.info(impcomponentvalues)
impcomponentvalues.each { impcomponentvalue ->
Issue issue = impcomponentvalue as MutableIssue
if(issue.getIssueType().name == "Component") {
def typeofcomponent = impcomponentvalue.toString()
MutableIssue childissue = ComponentAccessor.getIssueManager().getIssueObject(typeofcomponent)
def cField = customFieldManager.getCustomFieldObjectByName("Type of Component")
def val = childissue.getCustomFieldValue(cField).toString()
typecomponentset.add(val)
}
else if(issue.getIssueType().name == "Flow") {
def typeofcomponent = impcomponentvalue.toString()
MutableIssue childissue = ComponentAccessor.getIssueManager().getIssueObject(typeofcomponent)
def cField = customFieldManager.getCustomFieldObjectByName("Type of Flow")
def val = childissue.getCustomFieldValue(cField).toString()
typeflowset.add(val)
}
else {
log.info("other technical component")
}
}
log.info(typecomponentset)
def query = jqlQueryParser.parseQuery("project = DD AND \"Type of Impacted Technical Component\" = Batch")
def search = searchService.search(user, query, PagerFilter.getUnlimitedFilter())
search.getIssues().each { documentIssue ->
def dod = issueManager.getIssueObject(documentIssue.id)
log.info(dod.summary)
batchset.add(dod.summary.toString())
}
def query1 = jqlQueryParser.parseQuery("project = DD AND \"Type of Impacted Technical Component\" = Interface")
def search1 = searchService.search(user, query1, PagerFilter.getUnlimitedFilter())
search1.getIssues().each { documentIssue1 ->
def dod1 = issueManager.getIssueObject(documentIssue1.id)
log.info(dod1.summary)
interfaceset.add(dod1.summary.toString())
}

int i = 0;
batchset.each { e ->
xml."ac:task-list"{
"ac:task"{
"ac:task-id"(i++)
"ac:task-status"("incomplete")
"ac:task-body"(e.toString())
}
}
}
int j = i + 0 ;
interfaceset.each { e ->
xml1."ac:task-list"{
"ac:task"{
"ac:task-id"(j++)
"ac:task-status"("incomplete")
"ac:task-body"(e.toString())
}
}
}
def params = [
title: "${issue.key}" + " : " + "${issue.summary}",
tamplateid : 15859716 ,
key : issue.key ,
summary : issue.summary ,
batchset : writer.toString() ,
interfaceset : writer1.toString()
]


def authenticatedRequestFactory = confluenceLink.createImpersonatingAuthenticatedRequestFactory()
authenticatedRequestFactory
.createRequest(Request.MethodType.POST, "/rest/scriptrunner/latest/custom/createpagefromtitle")
.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"] // In this line it is showing the error 
}
}
})

Sushma September 25, 2019

The Application linking between Jira and confluence is as below

connection.PNG

Sushma September 26, 2019

Hi @fran garcia gomera 

is there any way to resolve this ?

Thanks & Regards

Sushma

Suggest an answer

Log in or Sign up to answer