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?
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:
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')
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did you tried this in Script Console?
It will not display this log, because this code runs in another thread.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No, what I want is when user creates linked issue from Epic issue, then make transition to "desired status" of Epic issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Are you putting the post-function after the step of "issue created"?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.
Online 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.