Using Behaviours plugin to set assignee from issue type

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

1 answer

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

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. grafik.png

grafik.png

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 :(

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Apr 10, 2018 in Marketplace Apps

Learn about how Stefan K. built one of the *first ever* Marketplace apps

In this post you will discover more about the evolution of K15t software, some big topics they're currently focusing on in the app space, and a rare (not not funny!) photo of founders Mike Cannon-Bro...

13,109 views 11 24
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you