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)
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:
10000 | Blocks | is blocked by | blocks | |
10001 | Cloners | is cloned by | clones | |
10002 | Duplicate | is duplicated by | duplicates | |
10003 | Relates | relates to | relates to | |
10100 | jira_subtask_link | jira_subtask_inward | jira_subtask_outward | jira_subtask |
10200 | Epic-Story Link | has Epic | is Epic of | jira_gh_epic_story |
10300 | Gantt End to Start | has to be done after | has to be done before | |
10301 | Gantt Start to Start | has to be started together with | has to be started together with | |
10302 | Gantt End to End | has to be finished together with | has to be finished together with | |
10303 | Gantt Start to End | start is earliest end of | earliest end is start of | |
10400 | Complements | Is complemented by | Complements | |
10500 | Problem/Incident | is caused by | causes | servicedesk_automation_default_linktype |
sorry i can't help more
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
Workflow conditions
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Share the script code, pal
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
}
}
})
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.
Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.
Register NowOnline forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.