Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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
Asked in Jira Service Management

JSM June ask me anything (AMA)

Hello Community members! We’re wrapping up the end of JSM June with an Ask Me Anything (AMA) with the Jira Service Management product team. This is your chance to ask all your ITSM questions to o...

285 views 14 14
View question

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