Forums

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

No signature of method: com.atlassian.jira.bc.issue.DefaultIssueService.validateTransition()

Pavel September 11, 2023

The script throws an error while running


def transitionValidationResult = issueService.validateTransition(ComponentAccessor.jiraAuthenticationContext.loggedInUser, issue.id, actionId, issueInputParameters, transitionOptions);

 

2023-09-11 19:15:16,629 ERROR [common.UserScriptEndpoint]: *************************************************************************************
2023-09-11 19:15:16,629 ERROR [common.UserScriptEndpoint]: Script console script failed:
groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.bc.issue.DefaultIssueService.validateTransition() is applicable for argument types: (com.atlassian.jira.user.DelegatingApplicationUser, java.util.ArrayList, java.lang.Integer, com.atlassian.jira.issue.IssueInputParametersImpl, com.atlassian.jira.workflow.TransitionOptions) values: [qwerty(JIRAUSER23210), [264340], 11, com.atlassian.jira.issue.IssueInputParametersImpl@4b3b29c0, ...]
Possible solutions: validateTransition(com.atlassian.jira.user.ApplicationUser, java.lang.Long, int, com.atlassian.jira.issue.IssueInputParameters, com.atlassian.jira.workflow.TransitionOptions), validateTransition(com.atlassian.jira.user.ApplicationUser, java.lang.Long, int, com.atlassian.jira.issue.IssueInputParameters)
at Script3882.doTransition(Script3882.groovy:27)
at Script3882$_findOutwardLinkedIssues_closure1.doCall(Script3882.groovy:49)
at Script3882.findOutwardLinkedIssues(Script3882.groovy:41)
at Script3882.run(Script3882.groovy:10)


My user is passed "values: [qwerty(JIRAUSER23210)" is it ok? should it be just qwerty?

What to do in this case?

1 answer

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
September 11, 2023

Hi @Pavel

Could you please provide more information, i.e. what ScriptRunner component are you using for this code? Is it Post-Function, Validator, Listener? And what exactly are you trying to do?

Also, could you please share your full code so I can review it and provide a better solution?

I am looking forward to your feedback.

Thank you and Kind regards,

Ram

Pavel September 12, 2023

Hi @Ram Kumar Aravindakshan _Adaptavist_ thank you for your response. I try to make a post-function that will change a status of a linked issue.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.util.JiraUtils
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl
import com.atlassian.jira.workflow.TransitionOptions
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.user.ApplicationUser


def issue = ComponentAccessor.issueManager.getIssueObject('TEST-1621')
findOutwardLinkedIssues(issue, 'Cause')

def doTransition(issue, int actionId, user, boolean skipConditions, boolean skipPermissions, boolean skipValidators){
def builder = new TransitionOptions.Builder()

if(skipConditions){
builder.skipConditions()
}
if(skipPermissions){
builder.skipPermissions()
}
if(skipValidators){
builder.skipValidators()
}
def transitionOptions = builder.build()
def issueService = ComponentAccessor.getIssueService()
def issueInputParameters = issueService.newIssueInputParameters();
def transitionValidationResult = issueService.validateTransition(ComponentAccessor.jiraAuthenticationContext.loggedInUser, issue.id, actionId, issueInputParameters, transitionOptions);
if (transitionValidationResult.isValid()) {
issueService.transition(user, transitionValidationResult);
return true
} else {
def issueResult = issueService.transition(user, transitionValidationResult)
log.warn("errors: ${issueResult.errorCollection}")
return false
}
}

def findOutwardLinkedIssues(Issue issue, String linkType) {
def links = ComponentAccessor.issueLinkManager.getInwardLinks(issue.id)
links.each {
log.info(it.issueLinkType.name)
if (it.issueLinkType.name == linkType) {
def linkedIssue = it.getDestinationObject()
if (linkedIssue.status.name != 'Closed') {
def linkedIssues = []
linkedIssues.add(linkedIssue)
ApplicationUser user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
doTransition(linkedIssues, 11, user, true, true, true)

}
}
}
}

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
September 13, 2023

Hi @Pavel

In your latest comment, you mentioned:-

I try to make a post-function that will change a status of a linked issue.

To achieve this, I suggest you upgrade your ScriptRunner plugin to the latest release, i.e. 8.11.0 or at least 7.11.,0 so you can make use of the ScriptRunner HAPI feature.

For your requirement, if you intend to transition any of your linked issues with ScriptRunner's HAPI, all you have to do is:-

issue.outwardLinks.each {
it.destinationObject.transition('In Progress')
} 

Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below is a screenshot of the configuration:-

post_function_config.png

Below are a couple of test screenshots for your reference:-

1. As shown in the first two screenshots below, MOCK-1 is linked to MOCK-2, where MOCK-1 blocks MOCK-2.

test1.png

test2.png

 

2. Next, when I transition MOCK-1 to In Progress, as shown in the next two screenshots below, as expected, MOCK-2 also transition to In Progress, as shown in the last screenshot below.

test3.png

test4.png

test5.png

I hope this helps to solve your question. :-)

Thank you and Kind regards,

Ram

Pavel September 13, 2023

Hi @Ram Kumar Aravindakshan _Adaptavist_ thank you for your reply.

Is there a way to implement it in Groovy?

HAPI is a good option but other engineers don't know this language, we agreed to write everything in Groovy. 

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
September 13, 2023

Hi  @Pavel

HAPI is built in the Groovy 4 API.

It's a much simpler approach to do this using the HAPI feature instead of writing multiple lines of the code. This also helps to reduce coding errors.

If you intend to use the plain Groovy approach is also fine, but as I mentioned, HAPI is very much simpler.

You can also refer to HAPI's Javadocs for more information.

Thank you and Kind regards,
Ram

Suggest an answer

Log in or Sign up to answer