Hello,
I have a script that is looking into the Customer Request Type and depending on it, it updates a custom field called "IT Change Type" with the correct option. Options are "Norma", "Retro" and "Urgent".
Here is the code:
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;
}
It seems like everything is working fine but the issue is not updated. Here is a sample log:
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
The script finds the option to the field correctly and the field itself but doesn't update the issue with the new value. There are no errors which is weird.
Any ideas?
Alex