Forums

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

Cannot make a transition in post function issue A if condition of ScriptRunner of issue B is enabled

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

I have a condition of ScriptRunner for a transition "In-progress":

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue

...
passesCondition = (showTransition == true);

and the above condition hides workflow button "in-progress". And it is a desired behaviour.

However, when I use post-function of another issue to make above transition "in-progress", then transition is not happened. But if I disable
a condition for a transition "In-progress", then transition is executed perfectly.


Schematically, it looks like this:

- issue A does not have workflow button 'in-progress' as there is a condition of ScriptRunner
- issue B tries to make transition of issue A, but there is no result. However, if I disable a ScriptRunner condition, then issue B makes perfectly a transition of issue A

My question is how can I make a transition in post function with enabled condition of ScriptRunner?

2 answers

1 accepted

1 vote
Answer accepted
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 10, 2018

Hello @zaharovvv_suek_ru

How exactly are you doin this transition, can you provide some code?

There are some methods that allow to skip conditions and validators check

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 11, 2018

Hey, @Mark Markov. The whole code looks like this:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.issue.IssueManager
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.event.type.EventDispatchOption;
import com.opensymphony.workflow.loader.ActionDescriptor
import com.opensymphony.workflow.loader.StepDescriptor
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.IssueInputParametersImpl


def issueLinkManager = ComponentAccessor.getIssueLinkManager()
issueLinkManager.getOutwardLinks(issue.id).each{ issueLink ->
def linkedIssue = issueLink.getDestinationObject()
log.info('3.1. ***** LinkedIssue: *****' + linkedIssue)
log.info('3.2. ***** IssueType of LinkedIssue: *****'
+ linkedIssue.getIssueType().getName())
if(linkedIssue.getIssueType().getName() == 'Epic') {
log.info('3.3. issue type is Epic. We have got it!')
def workflowManager = ComponentAccessor.getWorkflowManager()
def workflow = workflowManager.getWorkflow(linkedIssue);
def currentUser = ComponentAccessor.getJiraAuthenticationContext()
.getLoggedInUser()
StepDescriptor stepDescritpor = workflow
.getLinkedStep(linkedIssue.getStatus())
List<ActionDescriptor> outActions = stepDescritpor.getActions()
outActions.collect { actionWork->
log.info('4.1. *** Section action name is riched. ***')
log.info('4.2. Action Work Name: ' + actionWork.name)
log.info('4.3. *** Section action name is riched. ***')
//In-progress
if(actionWork.name == 'In-progress') {
def transitionId_InProgress = actionWork.id;
log.info('5.1. *** transitionId_InProgress: '
+ transitionId_InProgress)

if(transitionId_InProgress > 0) {
log.info('6.1. actionWork.name ' + actionWork.name +
' . Action Work id: ' + actionWork.id
+ ' . transitionId_InProgress: '
+ transitionId_InProgress)
def issueService = ComponentAccessor.getIssueService();
def issueInputParameters = issueService
.newIssueInputParameters();
IssueService.TransitionValidationResult validationResult=
issueService.validateTransition(currentUser,
linkedIssue.id, transitionId_InProgress as Integer,
new IssueInputParametersImpl())
def errorCollection = validationResult.errorCollection

log.info('9.3. transition section:')
if ( !errorCollection.hasAnyErrors()) {
log.info('9.3. transition section. Successful.
LinkedIssue: ' + linkedIssue)
issueService.transition(currentUser, validationResult)
}
else {
log.info('9.3. transition section. Something wrong here.
LinkedIssue: ' + linkedIssue)
log.info(errorCollection)
}
transitionId_InProgress = 0;
log.info('9.3. transitionId_InProgress is set to 0: '
+ transitionId_InProgress);
}
}
}
}
}

And the above code cannot make a transition if there is a condition of transition of ScriptRunner. 

Alexey Matveev
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 11, 2018

You can use this method to validate transition:

validateTransition(@Nullable
                                                           ApplicationUser user,
                                                           Long issueId,
                                                           int actionId,
                                                           IssueInputParameters issueInputParameters,
                                                           TransitionOptions transitionOptions)

In TransitionOptions you can skip conditions

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 11, 2018

@Alexey Matveev Thanks for suggestion!

I've tried your method:

IssueService.TransitionValidationResult validationResult = issueService
.validateTransition(
@Nullable, currentUser, linkedIssue.id,
transitionId_Refinement as Integer,
new IssueInputParametersImpl())


however I see the following error:

The script could not be compiled: <pre>org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script332.groovy: 56: unable to resolve class Nullable , unable to find class for annotation @ line 56, column 116. sueService.validateTransition(@Nullable, ^ 1 error </pre>.

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 11, 2018

As @Alexey Matveev says you need use method with TransitionOptions object.

It should be like this

import com.atlassian.jira.workflow.TransitionOptions;

TransitionOptions transitionOptions = new TransitionOptions.Builder().skipConditions().skipPermissions().skipValidators().build();
.
.
.
IssueService.TransitionValidationResult validationResult = issueService.validateTransition(currentUser, linkedIssue.id, transitionId_InProgress as Integer, new IssueInputParametersImpl(), transitionOptions)
Like Marina Veselić likes this
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 11, 2018

@Mark Markov

Thank you very much! The transition is executed! :)

2 votes
Alexey Matveev
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

Hello,

Make a separate transition (for example, name it autoInProgress) and set the Hide transition form user condition for this transition. In your script you can execute the autoInProgress 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.
July 11, 2018

@Alexey Matveev

I've tried your approach and created a separate transition "InProgressHidden". Then I've added a condition "Hide transition from user". So transition "InProgressHidden"  cannot be seen by users. And it is desired behaviour.

However, if I try to make a transition "InProgressHidden" by workflow function, then the transition "InProgressHidden" is not happened.

If I turn off a condition "Hide transition from user", then transition executes perfectly.

The code that I am using to make the transition "InProgressHidden":

 

 

if(actionWork.name == 'InProgressHidden') { 
def transitionId_InProgressHidden = actionWork.id;
log.info('5.1. *** InProgressHidden: ' + InProgressHidden)

if(InProgressHidden > 0) {
log.info('6.1. actionWork.name ' + actionWork.name
+ ' . Action Work id: ' + actionWork.id
+ ' . InProgressHidden: ' + InProgressHidden)
def issueService = ComponentAccessor.getIssueService();
def issueInputParameters = issueService.newIssueInputParameters();
IssueService.TransitionValidationResult validationResult=
issueService.validateTransition(currentUser,
linkedIssue.id, InProgressHidden as Integer,
new IssueInputParametersImpl())
def errorCollection = validationResult.errorCollection

log.info('7.1. transition section:')
if ( !errorCollection.hasAnyErrors()) {
log.info('7.2. transition section. Successful.LinkedIssue: '
+ linkedIssue)
issueService.transition(currentUser, validationResult)
}
else {
log.info('7.3. transition section. Something wrong here.
LinkedIssue: ' + linkedIssue)
log.info(errorCollection)
}
InProgressHidden = 0;
log.info('9.3. InProgressHidden is set to 0: ' + InProgressHidden);
}
}

It seems that I am doing something wrong. Could you tell me what I am doing wrong?

Suggest an answer

Log in or Sign up to answer