Script runner - setting selection list field value

i'm trying to set a custom selection list field value via script runner post function script.

It passes with no issues but I don't see the filed actually getting updated. 

What am I missing ?

import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
def componentManager = ComponentManager.instance;
if (issue.issueTypeObject.name == "Bug"){
	def optionsManager = componentManager.getComponentInstanceOfType(OptionsManager.class);
// locating the custom field	
def cfDocReq = componentManager.getCustomFieldManager().getCustomFieldObjectByName('Documentation required');
	// retrieve the field options
	def fieldConfig = cfDocReq.getRelevantConfig(issue);
	// set up the specific value to set the list 
	def value = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find { it.toString() == 'Required' }
    // update the custom selection list field
	issue.setCustomFieldValue(cfDocReq, value);
	// store changes
	issue.store();
}

2 answers

1 accepted

This widget could not be displayed.

OK, this is how its suppose to be (working for me):

 

// setting the list value to null which is the default jira value
mutableIssue.setCustomFieldValue(cfSDoc, null);
// update the custom filed and issue
Map<String, ModifiedValue> modifiedFields = mutableIssue.getModifiedFields();
def fieldLayoutItem = ComponentManager.getInstance().getFieldLayoutManager().getFieldLayout(mutableIssue).getFieldLayoutItem(cfSDoc);
DefaultIssueChangeHolder issueChangeHolder = new DefaultIssueChangeHolder();
ModifiedValue modifiedValue = (ModifiedValue) modifiedFields.get(cfSDoc.getId());
cfSDoc.updateValue(fieldLayoutItem, mutableIssue, modifiedValue, issueChangeHolder);
mutableIssue.store();
This widget could not be displayed.

Anything ????

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted yesterday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

46 views 1 0
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you