Hi everyone
Simple question I think but I can't get it to work.
I would like to use the behaviours plugin from ScriptRunner to set and lock the assignee when the user selects a specific issue type and of course unlock it again when any other issue type gets selected.
I created a behaviour and mapped it to the desired project and issue type and then created an initialiser function like so.
if (getActionName() != "Create Issue") { return // not the initial action, so don't set default values } getFieldById("assignee").setFormValue("buraccop") getFieldById("assignee").setRequired(true) getFieldById("assignee").setReadOnly(true)
bh.PNG
However, the assignee remains on 'automatic' and the field does not get locked when I create a new issue.
What could be the issue here? Why does the initialiser not run?
Thanks for any help.
BR
Hi Marius
Sorry for the late response, you can try something like
import com.atlassian.jira.component.ComponentAccessor import com.onresolve.jira.groovy.user.FieldBehaviours import static com.atlassian.jira.issue.IssueFieldConstants.* import groovy.transform.BaseScript def assignee = getFieldById(ASSIGNEE) def issueTypeId = getFieldById(getFieldChanged()).getValue() as String def issueTypeName = ComponentAccessor.getConstantsManager().getIssueType(issueTypeId).name if (issueTypeName == "Bug") { assignee.setFormValue("admin") //set user using the username assignee.setReadOnly(true) } else { assignee.setFormValue("anuser") assignee.setReadOnly(true) }
You have to attach this behaviour on at the Issue Type field.
Please let me know if this does the trick.
Kind regards, Thanos
Hi Thanos,
I tried out the code for doing the following:
If the Checkbox "sofort abschließen" is checked the assignee should be set to the reporter and to read only too.
The user I tested with had all needed permissions. The Behaviour was attached to a Checkbox Customfield (cfAbschliessen in the Code).
As a result the assignee field was only set to read only but the user did not change.
Alternatives I tried you can see as comment lines in my code. No one of this lines worked.
import com.atlassian.jira.component.ComponentAccessor import static com.atlassian.jira.issue.IssueFieldConstants.* import com.onresolve.jira.groovy.user.FieldBehaviours import groovy.transform.BaseScript def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() def assignee = getFieldById(ASSIGNEE) def cfAbschliessen = getFieldById(getFieldChanged()).getValue() as String if (cfAbschliessen == "sofort abschließen") { //assignee.setFormValue("admin") // usage of the username //assignee.setFormValue(currentUser.getName()) //assignee.setFormValue(currentUser.getKey()) assignee.setFormValue(currentUser.getUsername()) assignee.setReadOnly(true) } else { assignee.setReadOnly(false) }
Can you give me a hint how I can change the assignee?
Thx.
King regards
Roman
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm having the same issue as Roman. The field does not show my specified user and ist still set to 'Automatic'. I tried using debug messages and apparently, the value of the variable assignee changes but it has no effect on my screen or the assignee after clicking Create.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Nevermind. I figured it out. The user has to be someone with the permission "assignable user" in said project and issuetype. I was testing with myself but forgot that.
However, resetting back to "Automatic" after changing the issuetype does still not work :(
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.