Hi All,
Here is my requirement -
I have a Group Picker field that has a value. I want to set the Comment field to required when someone changes the value.
My initial thought is to get the current value of the field and then compare it to the new value and then set Comment to required if true. So for example, if the field had the value "Foo" and someone edited it to "Bar" then set Comment to required. If the value didn't change then do not set Comment as required.
Here is the code I have currently -
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.*
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField customField = customFieldManager.getCustomFieldObjectByName("Group Field")
IssueManager issueManager = ComponentAccessor.getIssueManager();
MutableIssue issue = (MutableIssue) underlyingIssue;
Issue originalIssue = issueManager.getIssueObject(issue.id)
def oldValue = originalIssue.getCustomFieldValue(customField)
def customFieldOnForm = getFieldByName("Group Field")
def newValue = customFieldOnForm.getValue()
log.error "[DEBUG] oldValue is :: " +oldValue
log.error "[DEBUG] newValue is :: " +newValue
Output:
/rest/scriptrunner/behaviours/latest/runvalidator.json [c.o.j.groovy.user.FieldBehaviours][DEBUG] oldValue is :: [com.atlassian.crowd.embedded.impl.ImmutableGroup@9acac80d]
2018-03-22 14:25:55,096 http-nio-7999-exec-19 ERROR <> 865x332419x3 duah9u 139.49.147.10,10.73.139.2 /rest/scriptrunner/behaviours/latest/runvalidator.json [c.o.j.groovy.user.FieldBehaviours] [DEBUG] newValue is :: FOO
I would have expected oldValue to be FOO and newValue to be what I set it to from the Edit screen.
Any suggestions?
Thanks