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

0 votes

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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,760 views 11 18
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot