Forums

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

How to auto update the issue status on custom field value selection with Script runner?

mani@123
Contributor
July 11, 2019

Hello,

How to auto update the issue status on custom field value selection?

Example: we have an custom field called "Rejection" and it has options A & B if user selects option A issue should automatically move to Rejected status.

Thanks in Advance,

Mani

1 answer

1 accepted

0 votes
Answer accepted
Antoine Berry
Community Champion
July 15, 2019 edited

Hi mani@123 ,

Kindly try this script : 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.util.JiraUtils
import com.atlassian.jira.workflow.WorkflowTransitionUtil
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl

def customFieldManager = ComponentAccessor.getCustomFieldManager()

def selectListChanged = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "Rejection"}

if (selectListChanged){
int selectListId = 13500
def selectList = customFieldManager.getCustomFieldObject(selectListId)
def selectListValue = issue.getCustomFieldValue(selectList)

if (selectListValue?.getValue() == "A") {
def transitionId = 21
WorkflowTransitionUtil workflowTransitionUtil = (WorkflowTransitionUtil) JiraUtils.loadComponent(WorkflowTransitionUtilImpl.class);
workflowTransitionUtil.setIssue(issue);
workflowTransitionUtil.setUserkey("berry_a")
//Alternatively if you want to trigger the transition with the reporter use this
//workflowTransitionUtil.setUserkey(issue.getReporter().getKey())
workflowTransitionUtil.setAction(transitionId);
workflowTransitionUtil.progress();
}
}

 (replace custom field and transition id). Use this in script listener for Issue Updated event.

 Antoine

mani@123
Contributor
July 16, 2019

Thanks Antoine!!

Like • Antoine Berry likes this
Antoine Berry
Community Champion
July 17, 2019

Glad to help !

Suggest an answer

Log in or Sign up to answer