How to disable Components field by using Groovy Script?

Javier Portillo
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.
March 14, 2012

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

1 vote
Answer accepted
Javier Portillo
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.
March 20, 2012

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

Javier Portillo
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.
March 20, 2012

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

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.
March 20, 2012

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

Javier Portillo
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.
March 20, 2012

Sorry, im going to explain it better:

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

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.
March 20, 2012

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?

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.
March 21, 2012

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()

Javier Portillo
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.
March 22, 2012

Thanks! Now it works

0 votes
neil1967 October 18, 2012

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) 
}

0 votes
Javier Portillo
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.
March 18, 2012

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?

neil1967 October 18, 2012

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" ?

0 votes
Javier Portillo
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.
March 14, 2012

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

Thanks!

0 votes
Javier Portillo
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.
March 14, 2012

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

Thanks!

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.
March 14, 2012

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))

Javier Portillo
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.
March 14, 2012

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.

0 votes
Mizan
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.
March 14, 2012

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events