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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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

Aidan Derossett [Adaptavist]
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.
Oct 31, 2017

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
AUG Leaders

Atlassian Community Events