We have a custom field ("followUp") that has one value "Yes". This shows as a toggle button when we want to create an issue. However, when we transition it to a certain state we always want to set this "followUp" to "Yes". So far we have this much code:
CustomFieldManager fieldManager = ComponentAccessor.getCustomFieldManager() CustomField followUpField = fieldManager.getCustomFieldObjectByName("Follow-up") def followUp = issue.getCustomFieldValue(followUpField) //Now how do we set it to the value to "Yes" ?
Thanks for any hints.
I would guess that in this example the "follow up" field is a single checkbox, in which case you want to set it to a Collection<Option>
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.customfields.manager.OptionsManager def optionsManager = ComponentAccessor.getComponent(OptionsManager) def customFieldManager = ComponentAccessor.getCustomFieldManager() def cf = customFieldManager.getCustomFieldObjectByName("Checkboxes") // Checkboxes is the NAME of my custom field def fieldConfig = cf.getRelevantConfig(issue) def option = optionsManager.getOptions(fieldConfig).getOptionForValue("Yes", null) issue.setCustomFieldValue(cf, [option]) // <1>
This will work if this code runs before the system function to save the issue to the database.
Note that the Checkboxes is a multivalue field which is why the option variable is passed as an array
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, I copied and pasted from the docs code, more explanation here: https://scriptrunner.adaptavist.com/latest/jira/recipes/workflow/postfunctions/set-issue-attributes.html#_setting_checkbox_fields
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
def changeHolder = new DefaultIssueChangeHolder(); followUpField.updateValue(null, issue, new ModifiedValue(followUp, 1 as Integer),changeHolder);
Regards,
Petar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.