Hi everyone,
I would appreciate if someone could shed light on this, please.
I am a groovy learner, and I need to fulfill this requirement:
There are 2 checkbox custom fields: cf1, cf2 used in several issuetypes
In Create transition, there is a postfunction that fills in cf1, depending on other custom field, so each issue has different cf1 values.
The thing is that cf2 must be filled in with some values of cf1 that apply to that issue. That is:
when creating issue1, cf1 takes values: a,b,c,e. Then, cf2 checks a list, and takes b,c, because b,c are in that list.
when creating issue2, cf1 takes values: a,c,d. Then, cf2 checks a list, and takes c,d, because c,d are in that list.
The list depends on the issuetype, that is why I have decided to add a postfuntion in each workflow of each issuetype. This postfunction is placed after the postfunction to fill in cf1, and this is the code:
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.customFieldManager
def optionsManager = ComponentAccessor.optionsManager
def issueManager = ComponentAccessor.issueManager
def cf2 = customFieldManager.getCustomFieldObjectsByName("custom field 2")[0]
def cf1 = customFieldManager.getCustomFieldObjectsByName("custom field 1")[0]
def fieldConfig2 = cf2.getRelevantConfig(issue)
def options2 = optionsManager.getOptions(fieldConfig2)
def fieldConfig1 = cf1.getRelevantConfig(issue)
def options1 = optionsManager.getOptions(fieldConfig1)
for (x in options1) {
if (x == "b")
{
def optionsToSet = options2.findAll { it.value in ["b"] }
issue.setCustomFieldValue(cf2, optionsToSet)
}
if (x == "c")
{
def optionsToSet = options2.findAll { it.value in ["c"] }
issue.setCustomFieldValue(cf2, optionsToSet)
}
if (x == "d")
{
def optionsToSet = options2.findAll { it.value in ["d"] }
issue.setCustomFieldValue(cf2, optionsToSet)
}}
As I do not know how to compare options1 with a list, I have used "if" statements.
But it does not work. Any idea, please?
Thanks in advance.
Cheers,
Almu