How to show and hide custom field based on Component USING Behaviours scriptrunner

How can i show or hide some custom filed based on component . 9

2 answers

Hello Tasher,

This has already been answered by another adaptavist member here, if you need further assistance setting the behaviour, or you want another example more relevant to your case, let us know.

Cheers!

Dyelamos

How can i get the component value ??

Hello Tasher

As shown by the accepted answer in the previous link, you could do:

FormField fieldFF = getFieldByName("YOUR CUSTOM FIELD NAME HERE");
String fieldValue = fieldFF.getValue();

I would also recomend that you take a look at the behaviours documentation, which is filled with examples that might help you.

Good luck and if I can help you anymore let us know.

Dyelamos

Unable tout resolve class FormField 

I have this error i need to get thé name of component

may I please take a look at your full code? 

instead of using FormField, use def:

have your last 2 declarations in line 6 and 7 to be:

def fieldFF = ...
def fieldValue = ...

Now i don't have error on the code but it don't work 

A colleage has said that you could use the IDs instead of the names, might work better.

You can do that like this:

import static com.atlassian.jira.issue.IssueFieldConstants.*
def ff = getFieldById(COMPONENTS)

How to have the id of the component ??

copy and paste the code that I just sent you, the ID comes in the import that you see on the first line of the code, that import defines the variable COMPONENTS which will contain the ID of the component

It's the some without error but it don't work

At line 4:

ff.getvalue

Will be a Collection of ProjectComponent , not a String, since . That could be why it isn't working.

What can i do!?

Hello Tasher.

Next time, please copy and paste your code instead of taking a picture of your screen, it will be better for us both :)

Here is the code, it should work:

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import static com.atlassian.jira.issue.IssueFieldConstants.*

@BaseScript FieldBehaviours fieldBehaviours
def ff = getFieldById(COMPONENTS)
def values = ff.getValue()*.getName()
def component = getFieldbyId("customfield_15001")
def nameV = getFieldbyId("customfield_15004")
def quality = getFieldbyId("customfield_15007")
def company = getFieldbyId("customfield_15006")

nameV.setHidden(true)
company.setHidden(true)
quality.setHidden(true)

if(values.toString().contains("USB")){
    nameV.setHidden(false)
    company.setHidden(false)
    quality.setHidden(false)
}

If it doesn't let us know

Cheers

 

Error on Line 7 : spead operator can only be used on collection type1496831962321-1542449449.jpg

Tasher,

Please stop sending pictures, it makes it very hard to replicate your code because I have to type it, copy and paste it. 

That gives you an error because the editor cannot tell that ff.getValue() will return a collection. Just update the code ignoring that error. It should work.

Cheers

 

It was funny "Please stop sending pictures," and this guy didn't get it. Thanks for the code. It worked! 

Hi Jay. Which code?
Cheers!
DY

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Oct 11, 2018 in Marketplace Apps

You + one app + a desert island...

Hi all! My name is Miles and I work on the Marketplace team. We’re looking for better ways to recommend and suggest apps that are truly crowd favorites, so of course we wanted to poll the Community. ...

3,563 views 6 6
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