8/20/2015

JIRA Development: Getting Priorities by Name

If you want to set the priority of an issue in JIRA programmatically then you need the priorityID. This is how you get it when you only have the name (Major, Minor etc.).
String priorityID = null;
PriorityManager priorityManager = getPriorityManager();
List priorities = priorityManager.getPriorities();
for (Iterator iterator = priorities.iterator();iterator.hasNext();) {
  Priority priority = (Priority) iterator.next();
  String id = priority.getId();
  String name = priority.getName();
  if (name.equalsIgnoreCase(priorityName)){
    priorityID  = id;
  }
}
Once you have the prriorityID you can set it like that :
IssueInputParameters inputParameters = getIssueService().newIssueInputParameters();
inputParameters.setPriorityId(priorityID );


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

8/19/2015

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.