Forums

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

Change Issue Type using Behavior on Create Screen

Alvin
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.
December 9, 2018

Hi Community,

Can you advice me on what's wrong with my code? it seems not to work when I want to change the value of Issue Type (e.g. Bug to Problem) using the value of single select field.

Here's my code:

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

def regressionIssueField = getFieldById(getFieldChanged())
def regressedVersionField = getFieldByName("Issue Type")

String regressionIssueValue = regressionIssueField.getValue()

if (regressionIssueValue == "Sample") {
regressedVersionField.setFormValue("Service Request")
} else {
regressedVersionField.setFormValue("Service Request with Approvals")
}

2 answers

1 accepted

1 vote
Answer accepted
Tarun Sapra
Community Champion
December 10, 2018

Hello @Alvin

Please see the sample here

https://scriptrunner.adaptavist.com/latest/jira/recipes/behaviours/restricting-issue-types.html

Instead of using  

regressedVersionField.setFormValue("Service Request")

You can use (as the example in the link) i.e. use setFieldOptions (with value of the issueTYpes which you want to set)

issueTypeField.setFieldOptions(availableIssueTypes)

 

Tarun Sapra
Community Champion
December 10, 2018

Please see this sample as well

https://scriptrunner.adaptavist.com/latest/jira/recipes/behaviours/restricting-issue-types.html#_restricting_to_a_singe_issue_type

You can change the issueType value to Problem and then lock the value by making the field Read-only.

0 votes
Alvin
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.
December 10, 2018

Hi @Tarun Sapra, I just forgot to import this :

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

now it works fine. Thank you so much

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events