can i use the custom filed values based on the issue type ?

kiranmai genkolla
Contributor
June 18, 2020

can i use the custom filed values based on the issue type  

if the script runner .. help can anyone help me in the script 

requirement:

in the custom field(cascade)  there were ,1,2,3,4 values(in drop down) 

if the select the issuetype = bug .. the custom field need to display only 1,4

if issuetype= Story the custom field need to display 1,3,2

if issuetype = test-case the custom field need to display 3,4

 

2 answers

1 accepted

1 vote
Answer accepted
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 19, 2020

Ciao @kiranmai genkolla 

you can try with this code within ScriptRunner behaviour

import com.atlassian.jira.issue.Issue;

Issue issue = getUnderlyingIssue();
String issueType = issue.getIssueTypeObject().getName();

def myField = getFieldByName("YOUR FIELD NAME HERE");
if(issueType.equalsIgnoreCase("YOUR ISSUE TYPE"))){
//SET HERE THE BEHAVIOUR FOR YOUR FIELD
myField.set...
}

Please put this code associated to the first field appearing in the screen (ususally summary).

https://scriptrunner.adaptavist.com/5.6.8.1-jira8/jira/behaviours-api-quickref.html use this link to catch your desired behaviour for your field.

Fabio 

kiranmai genkolla
Contributor
June 25, 2020

Hi Fabio,

tried it in the behaviour

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

def selectcf = getFieldByName("Ticket Category")
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def customField = customFieldManager.getCustomFieldObject(selectcf.getFieldId())
def config = customField.getRelevantConfig(getIssueContext()) //getting error over here

 

please check and guide me in this

Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 25, 2020

Ciao @kiranmai genkolla ,

try this code 

import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.customfields.manager.OptionsManager;
import com.atlassian.jira.issue.fields.config.FieldConfig;
import com.atlassian.jira.issue.customfields.option.Options;

Issue issue = getUnderlyingIssue();
String issueType = issue.getIssueTypeObject().getName();

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
OptionsManager optionsManager = ComponentAccessor.getOptionsManager();

def myField = getFieldByName("Ticket Category");
if(issueType.equalsIgnoreCase("Incidents")){
CustomField customField = customFieldManager.getCustomFieldObjectByName("Ticket Category");
FieldConfig config = customField.getRelevantConfig(issue)
Options options = optionsManager.getOptions(config);
myField.setFieldOptions(options.findAll {it.value in ['Platform Customization']});
}
Like kiranmai genkolla likes this
kiranmai genkolla
Contributor
June 25, 2020

getting the warnings .. but its working 

thanks a lot

Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 25, 2020

You're welcome!

kiranmai genkolla
Contributor
June 25, 2020

hi fabio

as the field was cascade type . Can i also restrict the child value.

in the above script i restricted the parent values from the "ticket category" field 

Manoj
Contributor
June 4, 2023

@Fabio Racobaldo _Herzum_ Hello

I do have similar kind of requirement.

Currently i have custom field called- Finance service (which has 10 drop down values) as below FB-1,FB-2,FB-3,FB-4 and so on till FB-10.

and based on finance service selection another custom field called budget handler which has drop down values as BH-1,BH-2,BH3 and so on.

and in this project i have 2 issue types such IRB-1 and IRB-2 and now i want set up something like based on Issue Type IRB-1, only first drop down values get appear in custom field finance service and respectively Budget Handler. 

similarly wanted to set condition for issue type IRB-2,

could you pls guide me how to start with this.

 

Thanks

M

John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 4, 2023

Hi @Manoj 

It's always best to create a new question so more people will see it and can tailor answers to your specific case. 

Manoj
Contributor
June 5, 2023

@John Funk thanks, i have posted this as new question. 

0 votes
John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 19, 2020

Hi @kiranmai genkolla  - I am not clear what you are tying to do. Do you want to see different values in your pick list custom field based on the Issue Type selected? 

If so, you can add a new context to the custom field and based it on the issue type. Then you can add different values for that issue type. 

kiranmai genkolla
Contributor
June 19, 2020

need to use the same custom field (cascading type) for the different issuetype . created the context field but its not able to view the project name with the other issue type

John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 19, 2020

Can you post of a screenshot of your context for that issue type?

kiranmai genkolla
Contributor
June 21, 2020

contxt.JPGunable to view the project name if i use the new context field

John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 23, 2020

What project are you trying to connect the new context to? Do you already use that project with another Context? Can yo provide a full page view with all of the contexts?

kiranmai genkolla
Contributor
June 24, 2020

custom field(cascade)  there were ,1,2,3,4 values(in drop down) 

if the select the issuetype = bug .. the custom field need to display only 1,4

if issuetype= Story the custom field need to display 1,3,2

if issuetype = test-case the custom field need to display 3,4

John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 24, 2020

Can you share a full page screenshot of the Context page for that custom field? 

kiranmai genkolla
Contributor
June 24, 2020

IMG_20200624_223903.jpg

John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 24, 2020

So you need to create 3 new contexts - one for Bug, one for Test-case and one for Story.

Only put in the options you want for each one of those issue types. 

To create the new contexts, click on the Add new context link at the top. 

kiranmai genkolla
Contributor
June 24, 2020

If I click on add new context link 

Iam unable to get any project name in the drop-down of projects

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events