Forums

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

Autofill "Issue Type" field in JIRA using value in Custom Field

Lakshmi CH
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.
July 18, 2023

Hi Team,

Is it possible to autofill the "Issue Type" (especially sub-task) field in JIRA using the value in "Custom Field"?


When Custom Field is set to Value1, the issue type should automatically change to Sub-Task1.

When Custom Field is set to Value2, the issue type should automatically change to Sub-Task2.

When Custom Field is set to Value3, the issue type should automatically change to Sub-Task1.

--

--

 

1 answer

1 accepted

0 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
July 19, 2023

Hi @Lakshmi CH

If you intend to change the issue type to Bug, Story, Task, Epic or other non-Sub-Task issue types, the answer is yes it is doable.

However, it is not doable for Sub-Task as the Sub-Task must first have an existing parent.

Below is the working sample code if you intend to change it to a non-Sub-Task issue type:-

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import static com.atlassian.jira.issue.IssueFieldConstants.ISSUE_TYPE

@BaseScript FieldBehaviours behaviours
def sampleList = getFieldById(fieldChanged)
def sampleListValue = sampleList.value.toString()
def issueType = getFieldById(ISSUE_TYPE)

if (sampleListValue == 'Option 1') {
issueType.setFormValue('Bug')
} else if (sampleListValue == 'Option 2') {
issueType.setFormValue('Task')
} else if (sampleListValue == 'Option 3') {
issueType.setFormValue('Story')
} else if (sampleListValue == 'Option 4') {
issueType.setFormValue('Sub-task')
}

Please note the sample code above is not 100% exact to your environment. Hence, you will need to modify it accordingly.

Below is a screenshot of the Behaviour configuration:-

behaviour_config.png

Below are a couple of test screenshots for your reference:-

test1.png

test2.png

 

test3.png

I hope this helps to solve your question. :-)

Thank you and Kind regards,
Ram 

Lakshmi CH
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.
July 20, 2023

Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

Its not working for me. Did I miss anything ?
Sorry I forgot to inform the field Product Type is multi selection list. 

Please find attached screenshots for your reference.

pro1.PNG

pro2.PNG

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
July 20, 2023 edited

Hi @Lakshmi CH

In your case, you are testing with a Multi-Select List, not a single Select List.

But you cannot select multiple options from the List for this scenario. So it is pointless to convert the Multi-Select List value to a List as you have done, i.e.:-

...
...

@BaseScript FieldBehaviours behaviours
def ProductType = getFieldById(fieldChanged)
def ProductTypeValue = ProductType.value as List

Instead, convert the Multi-Select List value to a String, as shown below, and it will resolve your problem.

...
...

@BaseScript FieldBehaviours behaviours
def ProductType = getFieldById(fieldChanged)
def ProductTypeValue = ProductType.value as String

However, if you still need to convert the Multi-Select List value to a List to get the Behaviour to work, you will then need to change the if/else condition to:-

...
...

@BaseScript FieldBehaviours behaviours
def ProductType = getFieldById(fieldChanged)
def ProductTypeValue = ProductType.value as List

if (ProductTypeValue == ['Assortment']) {
issueType.setFormValue('Bug')
}
...
...

I hope this helps to solve your question. :-)

Thank you and Kind regards,

Ram

Lakshmi CH
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.
July 21, 2023

Thank you @Ram Kumar Aravindakshan _Adaptavist_ , Its working now, I was able to change the main (parent) issue type based on field value.  There is no possibility to change the sub-task. This is our main requirement "Change the sub-task(we have 4 sub-tasks) based on custom field value) ?

issuetype.PNG

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
July 21, 2023

Hi @Lakshmi CH

Great to hear the solution worked. :-)

In your last comment, you asked:-

There is no possibility to change the sub-task. This is our main requirement "Change the sub-task(we have 4 sub-tasks) based on custom field value) ?

No, this is not possible. Using the Issue Picker is impossible to switch to a Sub-Task type as the Sub-task issue type is not displayed.

Please accept the answer.

Thank you and Kind regards,
Ram

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, team '25 europe, atlassian event, barcelona 2025, jira, confluence, atlassian intelligence, rovo, ai-powered collaboration, developer tools, agile teams, digital transformation, teamwork solutions, atlassian conference, product announcements

🌆 Team '25 Europe registration is now open!

Join the largest European gathering of the Atlassian Community and reimagine what’s possible when great teams and transformative technology come together. Plus, grab your Super Fan ticket now and save over €1,000 on your pass before prices rise on 3 June.

Register now
AUG Leaders

Atlassian Community Events