Forums

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

Transition at creation

fuzzelmukkel May 6, 2019

Hey community,

 

i am trying to auto-transition an issue using a script listener depending on a linked issue but there is an error i don't really understand:

t seems that you have tried to perform a workflow operation (Done) that is not valid for the current state of this issue (FOSS-15). The likely cause is that somebody has changed the issue recently, please look at the issue history for details.

Although the issue history is empty at this time.

When I run the same code on the same issue in the script console, the transition works. Do you guys have any clue what possibly have gone wrong?

 

This is my code:

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.user.ApplicationUser


// only transition tasks
if (issue.issueType.name != "Task") {
log.warn("This is not a task!")
return
}

def issueService = ComponentAccessor.issueService
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def cfield = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_10108")
def linkedIssue = issue.getCustomFieldValue(cfield)
def changeHistoryManager = ComponentAccessor.changeHistoryManager



def actionId = 0
switch (linkedIssue.status.name) {
case "Done":
actionId = 31
break
case "In Progress":
actionId = 21
}

log.error(issue.status)


def issueInputParameters = issueService.newIssueInputParameters()
def validationResult = issueService.validateTransition(user, issue.id, actionId, issueInputParameters)

if (!validationResult.isValid()) {
log.error("invalid transition: ${actionId}")
log.error(validationResult.errorCollection)
log.error(validationResult.warningCollection)
return
}

def transitionResult = issueService.transition(user, validationResult)
if (!transitionResult.isValid()) {
log.error("failed transition")
return
}

 

3 answers

1 accepted

0 votes
Answer accepted
Sebastian Krzewiński
Community Champion
May 6, 2019

Hi

I also suggest use this script on transition (scripted post-function). If you use script runner I would think about use fast-track tranistion post-function. Using this you can very easy create condition what transition should be triggered.

 

Regards,

Sebastian

1 vote
Heiko Gerlach
Contributor
May 6, 2019

Hi,

why do you want to use a listener. I suggest to use a scripted postfunction instead, since you want to attach this feature to a transition anyhow, so there is no need for a listener. 

If you want to "Transition at creation" you just need to add the post function to the create transition. Make sure the issue is created before modifying any issue details. (so you have to move down in the post functions config)

 

Cheers

Heiko

PO@Accxia

0 votes
Marc Minten (EVS)
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.
May 6, 2019

Your issue is not clear.

Are you talking about

  • a scripted transition in a workflow PostFunction ???
  • a listener event script ("...using a script listener...") ? This does not seem to be a listener-type script ?

Suggest an answer

Log in or Sign up to answer