Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Hiding field based on component selection

Edited

Hi Team,

I want to hide some fields based on component/s selection.

If I Select components "a" 

Component.PNGthen in Cost Tab

Cost.PNG

Salesforce Cost and ESB Cost field should hide.  

below are my code which I coded in Behaviours

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.bc.project.component.ProjectComponentImpl;
import com.atlassian.jira.issue.fields.layout.field.FieldLayoutItemImpl.Builder;


def Cerilion_Cost = getFieldByName("Cerilion Cost");
def Salesforce_Cost = getFieldByName("Salesforce Cost");
def ESB_Cost = getFieldByName("ESB Cost");

def component =getFieldById("components");

if(component.getValue()=='a'){
Cerilion_Cost.setRequired(true);
Salesforce_Cost.setHidden(true);
ESB_Cost.setHidden(true);

}

 

The above code is not working , can anyone tell me where am doing mistake.

 

Thanks,

Parthiban

2 comments

Hey Parthiban!

I think you may just not be going down far enough with the component/s value. The component returns a map, and so in your condition your just checking if that returned map equals a string. You need to get the name attribute from the component like this:

def comp = getFieldById(getFieldChanged())
if(comp.value)
{
log.warn("Component: "+comp.value.name)
}

Try that out and see if it works for you! :D

Aidan

Hi Aidan,

 

Thanks for your reply, I got the selection and it works. Below are my code

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.bc.project.component.ProjectComponentImpl;
import com.atlassian.jira.issue.fields.layout.field.FieldLayoutItemImpl.Builder;
import com.atlassian.jira.bc.project.component.ProjectComponent
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.bc.project.component.ProjectComponent;
import com.onresolve.jira.groovy.user.FieldBehaviours;
import groovy.transform.BaseScript;
import org.apache.log4j.Logger;
import org.apache.log4j.Level;
import com.onresolve.jira.groovy.user.FormField;
import com.atlassian.jira.bc.project.component.ProjectComponentImpl

@BaseScript FieldBehaviours fieldBehaviours
def log = Logger.getLogger("com.acme.CreateSubtask");
log.setLevel(Level.DEBUG);

def CCost = getFieldById("customfield_10302");
def SCost = getFieldById("customfield_10303");
def ECost = getFieldById("customfield_10304");

def components =getFieldById("components");
def comp= components.getValue()*.getName();


if (comp.toString().contains('a')){
CCost.setHidden(false);
SCost.setHidden(true);
ECost.setHidden(true);
}
else if(comp.toString().contains('b')){
CCost.setHidden(true);
SCost.setHidden(false);
ECost.setHidden(true);
}
else if (comp.toString().contains('c')){
CCost.setHidden(true);
SCost.setHidden(true);
ECost.setHidden(false);
}

 

But the problem here is , my client having 53 components as per my above code I need to write more than 150 If and else if condition.

 

Do you have any smarter way to check the above code for 53 components.

Requirement : My client having total 53 component , they will be select one or many components at a time . Based on the selection I need to show the cost field.

 

Kindly share your thoughts.

 

Thanks,

Parthiban

Comment

Log in or Sign up to comment
TAGS
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

68 views 1 6
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you