Forums

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

Cannot read inward or outward links of newly created issue in post function

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.
July 4, 2018

I would like to make a transition of issue where the action "Create linked issue" is performed.

For example, I have an epic issue "epic issue 1" and its status "In-progress".
And an user clicks the button "Create linked issue" and Jira creates new issue named "Linked issue 1". After "Linked issue 1" is created by issue, then epic issue
"epic issue 1" should make a trancition to change its status from "In-progress" to "Code-review".

That is, what I want is when user creates linked issue from Epic issue, then make transition to  "desired status" of Epic issue.

To do that I created a post function in Workflow of issue "Linked issue 1" and would like to read the all outward links and inwards links of issue. The code looks like this:


if(issue.getIssueType().name == 'Bug'
|| issue.getIssueType().name == 'New Feature'){
def issueManager = ComponentAccessor.issueManager

log.info('***** Current Status. Start: *****')
log.info('Issue: ' + issue + '. Issue Type: ' +
issue.getIssueType().getName())
log.info('***** Current Status. Finish: *****')


def issueLinkManager = ComponentAccessor.getIssueLinkManager()


log.info('Start of Outward Links')
issueLinkManager.getOutwardLinks(issue.id).each{ issueLink ->
def linkedIssue = issueLink.getDestinationObject()
log.info('linkedIssue: ' + linkedIssue + ' . LinkedIssueType: '
+ linkedIssue.getIssueType().getName())
}
log.info('End of Outward Links')


log.info('Start of Inward Links')
issueLinkManager.getInwardLinks(issue.id).each{ issueLink ->
def linkedIssue = issueLink.getDestinationObject()
log.info('linkedIssue: ' + linkedIssue + ' . LinkedIssueType: '
+ linkedIssue.getIssueType().getName())
}
log.info('End of Inward Links')
}

However, what I see in Execution Information is ( there is no outward links and inwards links):

2018-07-04 13:24:01,033 INFO [workflow.ScriptWorkflowFunction]: ***** Current Status. Start: *****
2018-07-04 13:24:01,034 INFO [workflow.ScriptWorkflowFunction]: Issue: Test of Epic 6. Issue Type: New Feature
2018-07-04 13:24:01,034 INFO [workflow.ScriptWorkflowFunction]: ***** Current Status. Finish: *****
2018-07-04 13:24:01,034 INFO [workflow.ScriptWorkflowFunction]: Start of Outward Links
2018-07-04 13:24:01,035 INFO [workflow.ScriptWorkflowFunction]: End of Outward Links
2018-07-04 13:24:01,035 INFO [workflow.ScriptWorkflowFunction]: Start of Inward Links
2018-07-04 13:24:01,036 INFO [workflow.ScriptWorkflowFunction]: End of Inward Links

 

Guys, how is it possible to read outward links and inwards links of issue in post function?

5 answers

1 accepted

0 votes
Answer accepted
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.
July 10, 2018

Thank you very much for all of your efforts, guys!

Finally it has started to work!

It turns out that it was necessary to move  post function to  the last place after all steps:

Order of post function.png

0 votes
Mark Markov
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.
July 5, 2018

Hello @zaharovvv_suek_ru 

As @Dar Kronenblum metioned, it seems that links created after issue created. And in this case sleep() will not help you, because its just will wait sleep and only after sleep finish creation.

In this case you will need to run your code in different thread and in this thread put sleep()

So place postfunction on the last place in postfunction list and use code like this:

import com.atlassian.jira.component.ComponentAccessor

Thread thread = Thread.start {
sleep(2000)
if (issue.getIssueType().name == 'Bug'
|| issue.getIssueType().name == 'New Feature') {
def issueManager = ComponentAccessor.issueManager

log.info('***** Current Status. Start: *****')
log.info('Issue: ' + issue + '. Issue Type: ' +
issue.getIssueType().getName())
log.info('***** Current Status. Finish: *****')


def issueLinkManager = ComponentAccessor.getIssueLinkManager()


log.info('Start of Outward Links')
issueLinkManager.getOutwardLinks(issue.id).each { issueLink ->
def linkedIssue = issueLink.getDestinationObject()
log.info('linkedIssue: ' + linkedIssue + ' . LinkedIssueType: '
+ linkedIssue.getIssueType().getName())
}
log.info('End of Outward Links')


log.info('Start of Inward Links')
issueLinkManager.getInwardLinks(issue.id).each { issueLink ->
def linkedIssue = issueLink.getDestinationObject()
log.info('linkedIssue: ' + linkedIssue + ' . LinkedIssueType: '
+ linkedIssue.getIssueType().getName())
}
log.info('End of Inward Links')
}

 

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.
July 5, 2018

@Mark MarkovThank you for your reply!

I've put some logging information to your code sample:

 

log.info('***** No thread. Simple Test. Just Test *****')


Thread thread = Thread.start {
sleep(2000)
log.info('***** Thread is run! *****')
.....

And it seems that  "Thread.start() " method is not run cause I see just  the folowing logs:

2018-07-05 18:21:39,935 INFO [workflow.ScriptWorkflowFunction]: ***** No thread. Simple Test. Just Test *****

 

Maybe you have another suggestions?

Thanks in advance.

Mark Markov
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.
July 5, 2018

Did you tried this in Script Console?

It will not display this log, because this code runs in another thread.

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

@Mark Markov

No, Mark, I've tried code at post-function of Workflow.

My whole code looks like this and I've put this code into post function:

log.info('***** Hello, World! *****')
if(issue.getIssueType().name == 'Bug'
|| issue.getIssueType().name == 'New Feature'){

log.info('***** Current Status. Start: *****')
log.info('Issue: ' + issue + '. Issue Type: '
+ issue.getIssueType().getName())
log.info('***** Current Status. Finish: *****')

Thread thread = Thread.start {
sleep(2000)

issueLinkManager.getOutwardLinks(issue.id).each{ issueLink ->
def linkedIssue = issueLink.getDestinationObject()

if(linkedIssue.getIssueType().getName() == 'Epic') {
log.info('issue type is Epic')
def workflowManager = ComponentAccessor.getWorkflowManager()
def workflow = workflowManager.getWorkflow(linkedIssue);
def transitionId_OfReopenedStatus = 0;

def currentUser = ComponentAccessor
.getJiraAuthenticationContext().getLoggedInUser()
StepDescriptor stepDescritpor =
workflow.getLinkedStep(linkedIssue.getStatus())
List<ActionDescriptor> outActions = stepDescritpor.getActions()
outActions.collect { actionWork->
if(actionWork.name == 'Доп. требование') {
transitionId_OfReopenedStatus = actionWork.id;
log.info('*** transitionId_OfReopenedStatus: '
+ transitionId_OfReopenedStatus)
if(transitionId_OfReopenedStatus > 0) {
log.debug('actionWork.name ' + actionWork.name +
' . Action Work id: ' + actionWork.id +
' . transitionId_OfReopenedStatus: ' +
transitionId_OfReopenedStatus)
def issueService = ComponentAccessor.getIssueService();
def issueInputParameters = issueService
.newIssueInputParameters();
IssueService.TransitionValidationResult validationResult
= issueService.validateTransition(currentUser,
linkedIssue.id,
transitionId_OfReopenedStatus as Integer,
new IssueInputParametersImpl())
def errorCollection = validationResult.errorCollection

log.debug('transition section:')
if ( !errorCollection.hasAnyErrors()) {
log.debug('transition section. Successful.
LinkedIssue: ' + linkedIssue)
issueService.transition(currentUser,
validationResult)
}
transitionId_OfReopenedStatus = 0;
log.debug('transitionId_OfReopenedStatus is set to 0: '
+ transitionId_OfReopenedStatus);
}
}
}
}
}
}
}

and Execution Information looks like this:

2018-07-06 13:11:28,389 INFO [workflow.ScriptWorkflowFunction]: ***** Hello, World! New attempt! 1 *****
2018-07-06 13:11:28,390 INFO [workflow.ScriptWorkflowFunction]: ***** Current Status. Start: *****
2018-07-06 13:11:28,390 INFO [workflow.ScriptWorkflowFunction]: Issue: Test issue Bug. Issue Type: Bug
2018-07-06 13:11:28,390 INFO [workflow.ScriptWorkflowFunction]: ***** Current Status. Finish: *****

 

@Mark Markov maybe is there some another approach? 

0 votes
Dar Kronenblum
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.
July 4, 2018

Hi,

It's a bit problematic to read the linked issue in the create issue post function because the links are created after the create action is ended (basically after your post function is executed...)

Try to add sleep() function at the beginning of your script- it should work  

Dar

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.
July 5, 2018

@Dar Kronenblum

Thank you for your reply!

I've tried your suggestion: 

if (issue.getIssueType().name == 'Bug'
    || issue.getIssueType().name == 'New Feature') {
        def issueManager = ComponentAccessor.issueManager

        sleep(2000)

        ...

}

 However, there are no  linked issues. 
Maybe you have another suggestion?

Thanks in advance.

0 votes
Gezim Shehu [Communardo]
Community Champion
July 4, 2018

Hi,

 

Sorry cannot seem to follow you.

If you want Epic Issue to transition to 1 status, why exactly is the post function in the Linked Issue workflow?

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.
July 4, 2018

Hey, @Gezim Shehu [Communardo] thanks for question! 

I would like to make a transition of Epic issue because user creates a linked issue from Epic issue. And I run post function of newly created linked issue to make a transition of Epic issue.

In other words,  Epic issue -> Create linked issue -> Post Function of newly created issue makes a transition of Epic issue from "In-progress" to "Code review".

 

Am I right to use this approach to make a transition of Epic issue from newly created linked issue?

Gezim Shehu [Communardo]
Community Champion
July 4, 2018

Hmm,

I cannot tell 100%, but if I understood it correctly, this is what I suggest:

 

Epic Issue workflow , transition to "desired status goes here".

This transition contains post function to create linked issue.

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.
July 4, 2018

No, what I want is when user creates linked issue from Epic issue, then make transition to  "desired status" of Epic issue.

0 votes
Nir Haimov
Community Champion
July 4, 2018

Hi,

Are you putting the post-function  after the step of "issue created"?

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.
July 4, 2018

Yeah, after issue created. I can read name of newly created issue, however cannot read inward or outward links.

The image where I put post -function:Workflow and its post function with  arrow and text.png

Nir Haimov
Community Champion
July 4, 2018

Hi,

As Dar said:

It's a bit problematic to read the linked issue in the create issue post function because the links are created after the create action is ended (basically after your post function is executed...)

You can try her solution or, you can use listener.

Cheers,

Nir

Javier Sánchez February 14, 2019

It doesn't work in a Listener btw

Suggest an answer

Log in or Sign up to answer