I'm trying to set the field "Assignee" to "Unassigned" during opening a workflow transition screen. The reason for this is, that the user that executes the transition must assign the issue to a user that should do the next work on this issue.
To achieve this, I did:
- create a behaviour "Reset Assignee"
- set up a mapping to my test project
- set up an initialiser function (based on a script I found in a forum)
This is the initialiser script:
import groovy.transform.BaseScript
import com.onresolve.jira.groovy.user.FieldBehaviours
import static com.atlassian.jira.issue.IssueFieldConstants.UNASSIGNED_STATUS
@BaseScript FieldBehaviours fieldBehaviours
final String screenName = 'DEV Workflow Screen (2022)'
final String fieldName = "Assignee"
final String expectedValue = UNASSIGNED_STATUS
if (fieldScreen.name == screenName) {
def field = getFieldByName(fieldName)
log.warn "Try to set Assignee field to: " + expectedValue
log.warn "current Assignee: " + field.value
field.value == expectedValue ? field.clearError() : field.setError('This is not a valid value')
log.warn "Assignee set to: " + field.value
}
If I execute the workflow step, my transition screen opens and shows the defined error message below the assignee field. The log shows:
Assignee set to: fwinkler
current Assignee: fwinkler
Try to set Assignee field to: Unassigned
all lines with this prefix: "2022-03-24 10:53:40,053+0100 http-nio-8081-exec-43 url: /rest/scriptrunner/behaviours/latest/validators.json; user: fwinkler WARN fwinkler 653x18079188x1 zpj9g 172.29.241.147,0:0:0:0:0:0:0:1 /rest/scriptrunner/behaviours/latest/validators.json [c.o.scriptrunner.runner.ScriptBindingsManager]"
Any help would be highly appreciated.
Frank