- Create a custom field "abc" and its selection options are "aa","bb"
- In the post-function, I added the Custom script post-function. How to achieve the custom field "abc" equal to "aa" or "bb" and update it on the issue in groovy script?
- If I run the following code in JIRA, I got the following error: java.util.String cannot be cast to com.atlassian.jira.issue.customfields.option.Option. What should I do to achieve this feature? thanks a lot.
log = Category.getInstance("com.onresolve.jira.groovy.AutoCloseChildIssues");
def ComponentManager compoentManager = ComponentManager.getInstance();
def CustomFieldManager customFieldManager = compoentManager.getCustomFieldManager();
def CustomField deliverCycleField = customFieldManager.getCustomFieldObjectByName("customeTime");
def deliverCycleValue = issue.getCustomFieldValue(deliverCycleField);
def CustomField deliverCycleCountField = customFieldManager.getCustomFieldObjectByName("abc");
if (deliverCycleValue <= 16) {issue.setCustomFieldValue(deliverCycleCountField, "aa");
} else {
issue.setCustomFieldValue(deliverCycleCountField, "bb");
log.error("-------------------------------------------5" + "deliverCycleValue=" + deliverCycleValue);
}
def FieldLayoutItem fieldLayoutItem = compoentManager.getFieldLayoutManager().getFieldLayout(issue).getFieldLayoutItem(deliverCycleCountField);
DefaultIssueChangeHolder defaultIssueChangeHolder = new DefaultIssueChangeHolder();
def modifiedFields = issue.getModifiedFields();
final ModifiedValue modifiedValue = (ModifiedValue) modifiedFields.get(deliverCycleCountField.getId());
deliverCycleCountField.updateValue(fieldLayoutItem, issue, modifiedValue, defaultIssueChangeHolder);