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

Parthiban Oct 25, 2017

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

Parthiban Oct 31, 2017

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
Community showcase
Posted in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

667 views 7 0
Join discussion

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