This is from this forum thread
To update a custom field value in an issue , using the Jira API , is done with updateValue function
Sound easy ,till you see what values you need to pass to it
For cascade list it's even worse.
You have to build a map of your parent option and sun option like so:
addToCascadeList
MutableIssue cIssue = (MutableIssue) transientVars.get("issue"); CustomField categoryCF = ComponentManager.getInstance().getCustomFieldManager().getCustomFieldObjectByName("Category"); if (categoryCF == null \|\| \!(categoryCF.getCustomFieldType() instanceof CascadingSelectCFType)) { log.error("Expected customfield doesn't exist or doesn't have the expected type."); } // Obtain the FieldLayoutItem associated with the custom field for this issue FieldLayoutItem fieldLayoutItem = null; try { fieldLayoutItem = ComponentManager.getInstance().getFieldLayoutManager().getFieldLayout(cIssue).getFieldLayoutItem(categoryCF); } catch (FieldLayoutStorageException e) { e.printStackTrace(); } OptionsManager optionsManager = (OptionsManager)ComponentManager.getComponentInstanceOfType(OptionsManager.class); // The current value of the cascadingselect of this issue. Object cValue = categoryCF.getValue(cIssue); CustomFieldParams newValues = new CustomFieldParamsImpl(); /\* Example how to put in an empty value for parent and child. Note that the parent option gets keyvalue "null" and child keyvalue "1". \*/ newValues.put(null, null); newValues.put("1", null); ModifiedValue modifiedValue = new ModifiedValue(cValue, newValues); categoryCF.updateValue(fieldLayoutItem, cIssue, modifiedValue, new DefaultIssueChangeHolder()); /\* Example how to put in a certain value for parent and child. In this case, I already have the id of the options that I want to set. \*/ // TODO: nullchecks for options. // Get the corresponding parentoption object of the id. Option parentOptionObj = optionsManager.findByOptionId(new Long(parentOption)); List parentOptionColl = new ArrayList(); parentOptionColl.add(parentOptionObj); newValues.put(null, parentOptionColl); Option childOptionObj = optionsManager.findByOptionId(new Long(childOption)); List childOptionColl = new ArrayList(); childOptionColl.add(childOptionObj); newValues.put("1", childOptionColl); ModifiedValue modifiedValue = new ModifiedValue(cValue, newValues); categoryCF.updateValue(fieldLayoutItem, cIssue, modifiedValue, new DefaultIssueChangeHolder());
To get the customefield i have used the ManagerFactory:
ManagerFactory.getCustomFieldManager().getCustomFieldObject(new Long(CASCADE_LIST_FIELD_ID));
i did things a bit diffrent , and i know it always good to have several example so here is my function:
buildAndVersion.java
private void updateCascadeValue(CustomField buildList, MutableIssue issue, String versionName, String buildValue, long cascadeListFieldId) { Options op = getOptions(cascadeListFieldId); CustomFieldParams newValues = new CustomFieldParamsImpl(); Option parentOptionObj = op.getOptionForValue(versionName, null); List parentOptionColl = new ArrayList(); parentOptionColl.add(parentOptionObj); newValues.put(null, parentOptionColl); Option childOptionObj = op.getOptionForValue(buildValue, parentOptionObj.getOptionId()); List childOptionColl = new ArrayList(); childOptionColl.add(childOptionObj); newValues.put("1", childOptionColl); Object oldValues = null; buildList.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(buildList), newValues), new DefaultIssueChangeHolder()); issue.store(); }
Thanks BAS for figuring this one out
