Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to script a default issue type for a project

Rajat Gupta April 22, 2016

I am trying to use behavior in  script runner to default to a particular issue type. However, when I try to do with following code, though it defaults to the required issue type "ABC", it does not allow any other issue type to be selected. Please let me know what modifications are required in the code.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager

import static com.atlassian.jira.issue.IssueFieldConstants.ISSUE_TYPE
def constantsManager = ComponentAccessor.getConstantsManager()
    def queryIssueType = constantsManager.getAllIssueTypeObjects().find { it.name == "ABC" }
   def  IssueType = getFieldById(ISSUE_TYPE)
        IssueType.setFormValue(queryIssueType.id)

3 answers

0 votes
JamieA
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.
April 22, 2016

You can't really do this with behaviours. Every time the issue type changes, it will load and apply any behaviours for that project and issue type combination. This is because you can assign behaviours to just certain issue types.

So when you change the issue type, it fires, and changes it back.

0 votes
Chris Dunne
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.
April 22, 2016

I am no expert on scriptrunner but I think what this code is doing is setting the value of the dropdown to your issue type. This would overwrite the values (i.e. all your issues types) that were previously there.

But what you really want is to set the default option value for the drop down which is done via the optionsManager.

I think you should try to do what is described here.

Chris

0 votes
Chris Dunne
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.
April 22, 2016

Why not use the default issue setting in the issue type scheme for the project?

Rajat Gupta April 22, 2016

Because as per design of jira, it remembers the last Issue Type you used and defaults to this one the next time you create an issue.

tarakeswar_dubey January 15, 2019

Hello Rajat,

You were able to get it done?

Suggest an answer

Log in or Sign up to answer