JIRA Development: Setting Options in Custom Fields

Everyone I know uses JIRA, including me. Admit it, you´re using JIRA, too ;) 
I am always surprised when I find people using other Issue Tracking Software.
I am not only using JIRA, I am developing for it and with the great JIRA plugins SDK you can easiliy create and extend every possible plugin in JIRA. This is why I will post some tipps and snippets in the next days.

I am going to start with a problem that many of you will run into: How do you set am Option in a multi or single select custom field ? Example: Set the select field to select the "Option B" value. That´s how you do it:

public static Option getCustomFieldOption(String name, Issue issue, String ovalue){
  CustomField field= customFieldManager.getCustomFieldObjectByName(name);
  FieldConfig relevantConfig = field.getRelevantConfig(issue);
  Options options = optionsManager.getOptions(relevantConfig);
  Iterator iterator = options.iterator();

  while (iterator.hasNext()) {
    Option option = (Option) iterator.next();
    String value = option.getValue();
    if (value.equalsIgnoreCase(ovalue)){
      return option;
  return null;

If you have any questions, feel free to leave a comment.