How can I set the default Create Screen form value of Assignee per Issue Type using ScriptRunner? Edited

For one issue type (Bug), I would like to set the default value of the Assignee Field to a user called "Unconfirmed". By this I mean that users can still edit the assignee field on the Create Screen, but the field default shows as Unconfirmed.

(I'm not interested in automatic assignment using Post Functions in this scenario)

For all other issue types, I would like to set the default value of the Assignee Field to "Automatic"

 

I'm attempting to accomplish this using ScriptRunner Behaviors, but can't get it to work properly. The code below is what I have currently. I have tried this as both an initialiser function as well as a serverside script for the Assignee field. 

 

Any assistance is appreciated!

 

import com.atlassian.jira.component.ComponentAccessor

import static com.atlassian.jira.issue.IssueFieldConstants.*

if (getActionName() != "Create Issue") {
return
}

//Value of 1 = Bug Issue Type
if (getFieldById(ISSUE_TYPE).getFormValue() == 1)

{
getFieldById(ASSIGNEE).setFormValue("Unconfirmed")

}

else
{
getFieldById(ASSIGNEE).setFormValue("Automatic")
}

 

1 answer

This widget could not be displayed.

Hi Jordan,

You can't just set a random value like "Unconfirmed" or "Automatic" to the 'Assignee' field. Thing is, the 'Assignee' field is effectively a list of user objects, so you have to either select a user object as its value or set it to 'null' (which is displayed as "Unassigned").

That said may I suggest a slightly different approach to your issue? It is my understanding that you have a default assignee configured for all issue types within your project. With that in mind I'd like to suggest that you simply use a scripted post-function to change the assignee to 'Unassigned' when an issue is created if that issue happens to be a 'Bug' type?

To do that created a scripted post-function on your 'Create' transition using the code below. Also make sure that this post-function is placed right AFTER "re-index issue....." post-function.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.UpdateIssueRequest

if (issue.getIssueType().getName() == "Bug"){
/*choose the user who will be the used as issue updater*/
def updater = ComponentAccessor.getUserManager().getUserByName("username")
issue.setAssignee(null)
ComponentAccessor.getIssueManager().updateIssue(updater, issue, UpdateIssueRequest.builder().build())

}

Hi Ivan,

I appreciate the help, but as stated, I'm not interested in solving this problem through Post Functions. Particularly, in the Create Screen, I'd like to set a Default Assignee option, but still allow users to make a choice, rather than auto-assign after the transition.

I've been able to get the basics of this working (change default for Bugs) by using Initializer Functions in the Behaviors section of ScriptRunner. However, I can't figure out how to have the Default set for Bugs, then switch back to Automatic for all other Issue Types as the initializer only fires once.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

182 views 2 0
Join discussion

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