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

Irina Traff August 7, 2016

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

6 votes
JamieA
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.
August 7, 2016
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"})
Irina Traff August 7, 2016

thank you a lot.

problem solved

2 votes
Jonas Andersson
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.
August 7, 2016

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.

Irina Traff August 7, 2016

thank you a lot.

problem solved

1 vote
Irina Traff August 7, 2016

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);
0 votes
JamieA
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.
August 7, 2016

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

0 votes
Irina Traff August 7, 2016

But its not correct, can anyone help me ?

Suggest an answer

Log in or Sign up to answer