Forums

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

Post function transition dont work

Karim Belhadj
Contributor
October 27, 2018

Hello i did the same code in a post function , an error always appear , please can somone help me !!!

My code:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink
def issueService = ComponentAccessor.getIssueService()
def linkType = ["Cloners"]
// 6.x validateTransition wants a User, so we have to use getDirectoryUser()
// 7.x validateTransition wants an ApplicationUser, so remove the .getDirectoryUser() after we upgrade
def user = ComponentAccessor.getJiraAuthenticationContext().getUser().getDirectoryUser()
def linkMgr = ComponentAccessor.getIssueLinkManager()
// Look through the outward links

for (IssueLink link in linkMgr.getOutwardLinks(issue.id)) {
def destIssue = link.getDestinationObject()
// Does the name of the link match "Cloner" ?

if (linkType.contains(link.issueLinkType.name)) {

def destStatusObject = destIssue.getStatusObject()
// Is the status of the linked issue "En attente niveau 2" ?
if (destStatusObject.name == "En attente niveau 2") {
// Prepare our input for the transition

def issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.with {
setComment("Camera has been installed. Signs are needed before camera can be activated.")
setSkipScreenCheck(true)
}
// return destStatusObject.name
//return destIssue.id
// return user
// Validate transitioning the linked issue to "Signs Needed"
def validationResult = issueService.validateTransition(user, destIssue.id, 31, issueInputParameters)
return validationResult
if (validationResult.isValid()) {
// Perform the transition

def issueResult = issueService.transition(user, validationResult)
if (! issueResult.isValid()) {

log.warn("Failed to transition task ${destIssue.key}, errors: ${issueResult.errorCollection}")
}
} else {
log.warn("Could not transition task ${destIssue.key}, errors: ${validationResult.errorCollection}")
}
} else {
log.warn("Skipping link: ${link.issueLinkType.name} ${destIssue.key} ${destStatusObject.name} (wrong status)")
}
} else {
log.warn("Skipping link: ${link.issueLinkType.name} ${destIssue.key} (wrong type)")
}
}

 

 

 

 

 

 

 

error:

V2018-10-27 20:13:12,919 ERROR [runner.ScriptFieldPreviewRunner]: ************************************************************************************* 2018-10-27 20:13:12,919 ERROR [runner.ScriptFieldPreviewRunner]: Script field preview failed for field that has not yet been created groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.bc.issue.DefaultIssueService.validateTransition() is applicable for argument types: (com.atlassian.jira.user.BridgedDirectoryUser, java.lang.Long, java.lang.Integer, com.atlassian.jira.issue.IssueInputParametersImpl) values: [kimo:1, 10459, 31, com.atlassian.jira.issue.IssueInputParametersImpl@1eed919] Possible solutions: validateTransition(com.atlassian.jira.user.ApplicationUser, java.lang.Long, int, com.atlassian.jira.issue.IssueInputParameters), validateTransition(com.atlassian.jira.user.ApplicationUser, java.lang.Long, int, com.atlassian.jira.issue.IssueInputParameters, com.atlassian.jira.workflow.TransitionOptions) at Script1273.run(Script1273.groovy:31)

1 answer

0 votes
David October 27, 2018

Hello Karim.

I think that you are using a wrong type of user as parameter for the validate function.

Please try to get the user with getJiraAuthenticationContext().getLoggedInUser() instead.

Nice regards.

Karim Belhadj
Contributor
October 30, 2018

Solved thank you  @David

Suggest an answer

Log in or Sign up to answer