Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

link is not setting to another issue in post function of "Create" transition

zaharovvv_suek_ru
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.
November 6, 2018

I am creating an issue from Confluence page. So there is a link to a Conluence page at newly created Jira issue:

Issue links.png

 

 

I've created a post function and put this function on the last place of excution afer "Re-index an issue to keep indexes in sync with the database",
"Fire a Issue Created event that can be processed by the listeners." functions:

Order if post function.png

 

My code in post function:


def log = Logger.getLogger("com.acme.CreateSubtask")
log.setLevel(Level.DEBUG)

Logger.println('Start')
def rlm = ComponentAccessor.getComponent(RemoteIssueLinkManager)
log.info('1')
def links = rlm.getRemoteIssueLinksForIssue(issue)

Logger.println("Starting links print")
log.info('2')
def onlyConflueceLinks = links.each {
log.info('3')
if (it.applicationType == RemoteIssueLink.APPLICATION_TYPE_CONFLUENCE) {
// getting pageId
log.info('4')
def confluenceUrl = it.getUrl();
log.info('confluenceUrl: '+ confluenceUrl)
def pageId = confluenceUrl.substring(confluenceUrl.lastIndexOf('=') + 1)
def isNumber = false;
try{
if(Integer.parseInt(pageId)){
pageId = Integer.parseInt(pageId)
isNumber = true;
}
}
catch(NumberFormatException e) {
log.info('Not a number!')
}
// get issues at Confluence page by pageId
if(isNumber){
log.info('5')
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getUser()
def jqlSearch = "issue in (issuesWithRemoteLinksByGlobalId('appId=710bf4d7-7ee9-3527-bbe8-a27bb56c2fa2&pageId=${pageId}')) and issuetype=10000"
def query = jqlQueryParser.parseQuery(jqlSearch)
def searchResult = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter())
// if there is an issue
if(searchResult.total > 0) {
log.info(searchResult.issues.first())
def epicIssue = issueManager.getIssueObject(searchResult.issues.first().id)
log.info('epic issue is ' + epicIssue)
ef currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def linkMgr = ComponentAccessor.getIssueLinkManager()
log.info('issue is '+ issue)
log.info('epicIssue is ' + epicIssue)
linkMgr.createIssueLink(issue.getId(), epicIssue.getId(), 10334, 1, currentUser)
}
}
}
}

What I see in logs are just: 
1
2

 

How is it possible to set link to another issue in post function of "Create" transition?

0 answers

Suggest an answer

Log in or Sign up to answer