How to disable Components field by using Groovy Script?

Hi,

I have tried to inlclude javascript code and doesnt work. Any idea of how do it by using groovy script in Behaviours?

6 answers

1 accepted

Hi again,

Im trying to use the following script in Behaviours:

import com.onresolve.jira.groovy.user.FormField

FormField f = getFieldById(getFieldChanged())
FormField comps = getFieldById("components")
comps.setReadOnly( (f.getValue() as Boolean))

where f is a custom field of type text field and components is the default system field.

Im allways getting the following error in the log file:

2012-03-21 08:16:09,971 http-8090-1 ERROR admin 496x189x1 pfrjrf 127.0.0.1 /rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/runvalidator.json [onresolve.jira.groovy.BehaviourManagerImpl] Something went wrong with  method run in class 
java.lang.NumberFormatException: For input string: "fdgdfgd"

It seems that f require a number but it is a text field. Please help

Jira version 4.4.1 and plugin version 0.5.0

When I include the ! simbol in the condition it seems that works...but i get exactly the reverse effect

What version of jira and what of version of the plugin?

Sorry, im going to explain it better:

I want to set components field as readonly when other text custom field is not empty

There's no description of what you are trying to do. Is it set the components readonly if some other field is empty, or the converse? And what type of field is the other field?

Let's say my select field is called SelectListA, when it's empty I want the components to be writable, otherwise readonly:

OK, here it is

def isEmpty = getFieldByName("SelectListA").getFormValue() != "-1" // // -1 is None
def components = getFieldById("components")

components.setReadOnly(isEmpty)

If the other field is not a select list then use:

def isEmpty = getFieldByName("SomeTextField").getValue()

Thanks! Now it works

0 vote
Mizan Community Champion Mar 14, 2012

Yes you are right but i need to set it as disabled just when other field is empty. Ideas?

Thanks!

You can write a script to set it to readonly when the other field is empty, using the behaviours plugin.

FormField f = getFieldById(getFieldChanged())
FormField comps = getFieldById("components")
comps.setReadOnly(! (f.getValue() as Boolean))

I've tried this code but it doesnt work. Concretely I have this code associated the field IS (getFieldChanged):

import com.onresolve.jira.groovy.user.FormField

FormField f = getFieldById(getFieldChanged());
FormField comps = getFieldById("components");
comps.setReadOnly(f.getValue() as Boolean);

I get an IllegalArgumentException.

Yes you are right but i need to set it as disabled just when other field is empty. Ideas?

Thanks!

I've been trying the previous answer and it seems to work fine in the create issue screen but when I got ot the edit issue screen, it doesnt work and I get the following message in the log file:

No option found for customfield_18500 with value 12233

Somebody knows what to do?

I'm having the same issue. Anyone ever figure out why it seems to be getting the field, but trying to get the value throws an exception with the "No option found for customfield_xxxxx with value xxxx" ?

For me, this issue was related to trying to use the getValue() method instead of getFormValue(). I'm not sure if this is due to the fact that it's a custom field, or if it's a custom field that is of type Numeric Field. This wasn't working for me:

FormField fieldSummaryFlag=getFieldById("customfield_11210")   
FormField fieldSummary=getFieldById("summary")

if (fieldSummaryFlag.getValue().toInteger() == 1) {
 fieldSummary.setReadOnly(true) 
}

but this did work for me:

FormField fieldSummaryFlag=getFieldById("customfield_11210")   
FormField fieldSummary=getFieldById("summary")

if (fieldSummaryFlag.getFormValue().toInteger() == 1) {
 fieldSummary.setReadOnly(true) 
}

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published yesterday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

72 views 0 5
Read article

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