Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Set assignee to "Unassigned" in workflow screen using Scriptrunner Behaviours

Frank Winkler March 24, 2022

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

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Steve Thornhill
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 24, 2022

This doesn't answer your query on the function of behaviours, but couldn't you achieve the same function by just using a validator on the workflow to check that Assignee has been changed?

Frank Winkler March 24, 2022

Thanks Steve! I also thought of a validator at first. But the requirement is that the assignee should be set to "unassigned" when the transition screen is opened (and only in the screen's field). If I use a validator, I would set the assignee in the issue - and when the user closes the transition screen with Cancel it would stay "unassigned".

TAGS
AUG Leaders

Atlassian Community Events