How to set a new SelectCFType value to a custom field?

srinivasp
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.
March 14, 2012
IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
FieldLayoutItem fieldLayoutItemResolver = componentManager.getFieldLayoutManager().getFieldLayout(issue).getFieldLayoutItem(customField);
customField.updateValue(fieldLayoutItemResolver, issue, new ModifiedValue((SelectCFType) customField.getValue(issue), "Closed Issue"),changeHolder);

I am getting the following exception.

javax.script.ScriptException: javax.script.ScriptException: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'Known Issue Documented' with class 'com.atlassian.jira.issue.customfields.option.LazyLoadedOption' to class 'com.atlassian.jira.issue.customfields.impl.SelectCFType'

I know this is a type cast exception which is from the highlited code. can any one tell me how to get the reference of required SelectCFType object?

1 answer

1 accepted

2 votes
Answer accepted
srinivasp
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.
March 14, 2012
List<Option> options = optionsManager.findByOptionValue("Closed Issue");	
	log.debug(customField.getValue(issue).toString())
	for(Option option : options){
		if(option.getRelatedCustomField().getCustomField().getName().equalsIgnoreCase(customField.getName())){
			issue.setCustomFieldValue(customField, option);
			break;
		}
	}

Thats it!!!!

Suggest an answer

Log in or Sign up to answer