Hello,
I'm writing a code that depending on the Request Type from the portal it should update a custom field called "IT Change Type". The custom field has the options: "Normal", "Urgent" and "Retro". I'm getting the option for the custom field, and the custom field but it still doesn't update it.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
MutableIssue mutableIssue = (MutableIssue) issue;
log.info("issue: " + mutableIssue.toString());
def reqType = ComponentAccessor.customFieldManager.getCustomFieldObjectByName('Customer Request Type');
def reqTypeVal = mutableIssue.getCustomFieldValue(reqType).getValue();
log.info("Issue type: " + reqTypeVal);
def changeTypeId = 14430;
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def CustomField changeType = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(changeTypeId);
def fieldConfig = changeType.getRelevantConfig(issue);
switch (reqTypeVal) {
case "itcm/e89992e0-cbf1-4208-ad24-e8ea100f2c33":
def value = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find { it.toString() == 'Normal' };
log.info("field option: " + value.toString());
log.info("field name: " + changeType.toString());
mutableIssue.setCustomFieldValue(changeType, value);
break;
case "itcm/3b6cb133-0971-48c4-8b53-d5a49af828ca":
def value = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find { it.toString() == 'Urgent' };
log.info("field option: " + value.toString());
log.info("field name: " + changeType.toString());
mutableIssue.setCustomFieldValue(changeType, value);
break;
case "itcm/74b2e0f8-33ef-4a14-a905-f1ef7460d6ae":
def value = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find { it.toString() == 'Retro' };
log.info("field option: " + value.toString());
log.info("field name: " + changeType.toString());
mutableIssue.setCustomFieldValue(changeType, value);
break;
}
Sample log from the code:
2019-02-12 06:22:48,441 [http-nio-8080-exec-4] | issue: ITCM-66
2019-02-12 06:22:48,443 [http-nio-8080-exec-4] | Issue type: itcm/74b2e0f8-33ef-4a14-a905-f1ef7460d6ae
2019-02-12 06:22:48,444 [http-nio-8080-exec-4] | field option: Retro
2019-02-12 06:22:48,444 [http-nio-8080-exec-4] | field name: IT Change Type
But then the field in the issue is not updated even tho there are no visible errors.
Any idea?
Alex