Dear community,
I wrote a script which will set an single select field to an specific value in dependency to the condition. I already studied other community entries which referred to the same problem. Unfortunately non of them seems to have a usable answer, at least for me.
Please do not look how clean the code is. Its a test and I may added to to much unneeded libraries, during the attempt to solve the problem. The problem I got is that Jira / Groovy seems not to know the method to finally set the single select field.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.customfields.option.Options
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.CustomFieldManager
// Set CustomFieldManager
def customFieldManager = ComponentAccessor.getCustomFieldManager()
// Set IssueManager
def issueManager = ComponentAccessor.getIssueManager()
// Set UserManager
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def optionsManager = ComponentAccessor.getOptionsManager()
def customField = customFieldManager.getCustomFieldObjectByName("Grenzwert")
def config = customField.getRelevantConfig(issue)
def options = optionsManager.getOptions(config)
def optionGruen = options.find { it.value == "<span class='status-macro aui-lozenge aui-lozenge-success'>grün</span>" }
def optionGelb = options.find { it.value == "<span class='status-macro aui-lozenge aui-lozenge-success'>grün</span>" }
def optionRot = options.find { it.value == "<span class='status-macro aui-lozenge aui-lozenge-success'>grün</span>" }
def ausfallzeit = customFieldManager.getCustomFieldObjectByName("Ausfallzeit")
def system = customFieldManager.getCustomFieldObjectByName("Betroffenes System")
def myIssue = issue
// grün
if ( ausfallzeit <= 15 && ( system == "NetApp Filer" || system == "VMWare" || system == "Internet" )) {
customField.setFormValue(optionGruen.optionId)
} else if ( ( ausfallzeit > 15 && ausfallzeit <= 30 ) && ( system == "IVIS" || system == "Oracle" || system == "MS SQL" )) {
customField.setFormValue(optionGruen.optionId)
// gelb
} else if ( ( ausfallzeit > 30 && ausfallzeit <= 60 ) && ( system == "NetApp Filer" || system == "VMWare" || system == "Internet")) {
customField.setFormValue(optionGelb.optionId)
} else if ( ( ausfallzeit > 60 && ausfallzeit <= 120 ) && ( system == "IVIS" || system == "Oracle" || system == "MS SQL" )) {
customField.setFormValue(optionGelb.optionId)
// rot
} else if ( ( ausfallzeit > 60 && ausfallzeit <= 120) && ( system == "NetApp Filer" || system == "VMWare" || system == "Internet")) {
customField.setFormValue(optionRot.optionId)
} else if ( ausfallzeit > 120 && ( system == "IVIS" || system == "Oracle" || system == "MS SQL")) {
customField.setFormValue(optionRot.optionId)
}
// Updates the issue without additional activity entries
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)