It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How can I update a single select custom field with a post function groovy script?

The error I am receiving is 'Cannot cast object with class 'com.atlassian.jira.customfields.option.LazyLoadedOption' to class 'java.util.Map'.

 

I've tried a couple of ways resulting in the same error, but here is the code I am currently working with:

 import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira. issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.customfields.option.*

def issue = issue as MutableIssue
def issueManager = ComponentAccessor.getIssueManager()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def changeHolder = new DefaultIssueChangeHolder()
def user = ComponentAccessor.getUserManager().getUserByName("admin")
def optionsManager = ComponentAccessor.getOptionsManager()

def cf = customFieldManager.getCustomFieldObjects(issue).find{it.name == "Authorization processed result"}

Option breachedOption = ComponentAccessor.optionsManager.findByOptionId(199944)
Option notBreachedOption = ComponentAccessor.optionsManager.findByOptionId(199945)

 

cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf), notBreachedOption), changeHolder)

 

 

1 answer

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you