is it possible to set stepid from a groovy script?

Tomas Gustavsson
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.
August 14, 2020

I can transition an issue with a scriptrunner listnern and a groovy script, but the status name is not correct after transition, but my ticket is in the right position for next transition. 
is there a way to hard code the status name value ?  

2 answers

1 accepted

0 votes
Answer accepted
Tomas Gustavsson
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.
September 15, 2020

I think i have found the reason why it did not work. 
the Post Function step have the following tirgger 
Fire a Issue Resolved event that can be processed by the listeners.

And in my script listner my last event is Issue Update

image.png

Once i changed this to 

image.png

My script start to work as expected 

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 15, 2020

If you are transitioning an issue correctly (i.e. not setting a step id, but going through a transition), then the status will be correct.

I think you need to show us what you are doing in your script.

Tomas Gustavsson
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.
August 16, 2020

Hi, 

If i use the script below in scriptrunner console and transition my ticket to just befor the requested automation it works perfectly. 
But the "same" script (the if-statment for installation is the first thing i check in the listner otherwise all is the same. ) the issue is transition but the status value is incorrect. 

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.workflow.WorkflowManager
import com.atlassian.jira.workflow.JiraWorkflow
import com.atlassian.jira.workflow.WorkflowException
import com.atlassian.jira.bc.issue.IssueService.UpdateValidationResult
import com.atlassian.jira.bc.issue.IssueService.IssueResult
import com.atlassian.jira.bc.issue.IssueService

// Get a pointer to the issue
//----Activate if Consloe is used----------------------------------------------------
def issueManager = ComponentAccessor.getIssueManager()
def issue = issueManager.getIssueObject("ICTSHH-4917")
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
//-------------------------------------------------------------------------------------*/

if (issue.getStatus().getName() == "Installation"){
log.warn("Issue has status Installation")

Issue issueKey = issue
log.warn("issueKey = " + issueKey)

def LinkManagerissue = ComponentAccessor.getIssueLinkManager()
def issueLinks = LinkManagerissue.getInwardLinks(issueKey.getId())
def transitionResult
def workFlowManager = ComponentAccessor.getWorkflowManager()
def workflow = workFlowManager.getWorkflow(issue)

//-----Check what id's are available for transistions
//return workflow.getLinkedStep(issue.getStatus()).getActions().id

def actionId = 421
IssueService issueService = ComponentAccessor.getIssueService()

def transitionValidationResult = issueService.validateTransition(currentUser, issue.id, actionId,new IssueInputParametersImpl())
def issueInputParameters = issueService.newIssueInputParameters()
//------Check if transittion is possible
if (transitionValidationResult.isValid()) {
transitionResult = issueService.transition(currentUser, transitionValidationResult)
if (transitionResult.isValid())
{ log.warn("Transitioned issue $issue through action $actionId") }
else
{ log.warn("The transitionValidation is not valid")}
}

 

// validate update -------------
UpdateValidationResult updateValidationResult = issueService.validateUpdate(currentUser, issue.getId(), issueInputParameters)
//return UpdateValidationResult
return updateValidationResult.isValid()

if (updateValidationResult.isValid()){
// update the issue ----------
issueInputParameters.setStatusId("CUSTOMER ACCEPTANCE")
IssueResult updateResult = issueService.update(currentUser, updateValidationResult)
if (!updateResult.isValid()){
log.warn("error updateResult: " + updateResult.getErrorCollection().toString())}
} else {
log.warn("error: updateValidationResult" + updateValidationResult.getErrorCollection().toString())}

}

Below is the result i get using scriptrunner listeners

 

image.png

It shall look like this

image.png

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events