How can I get component name (componentID) for custom field script ?

Display custom field depends of selected component.
For expample.

Component web
Component wap

For component web i need to show customField1

 

 

def s = getComponentByName(componentName);
def d = customField1 // for web
if (componentName = "web")
d.setHidden(true);
else
d.setHidden(false);

log.error(s);
log.error(d);

5 answers

4 votes
import com.atlassian.jira.bc.project.component.ProjectComponent
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours behaviours

def cf = getFieldByName("Some Field")

def components = getFieldById("components").getValue() as List<ProjectComponent>
cf.setHidden(components.any {it.name == "web"})

thank you a lot.

problem solved

As an admin, goto Administration -> issues -> customfields -> copy link location from the edit button

it should look something like this: https://your.jira.address./secure/admin/EditCustomField!default.jspa?id=10101

There is the ID in the URL.

thank you a lot.

problem solved

Problem solved:

init script

def s = getFieldByName("customField1");
s.setHidden(true);

 

validation script

def s = getFieldById(fieldChanged);
def d = getFieldByName("customField1");
if (s.getValue().get(0).getName().equals("web"))
d.setHidden(false);
else
d.setHidden(true);

But its not correct, can anyone help me ?

0 votes

that will throw an exception when a component is removed and it's empty

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,965 views 12 18
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot