Using behaviours plugin to make field required on condition

NickW November 11, 2013

Hi All

I am trying to implement that on the selection of a particular component that another custom field becomes required. I am trying to do this in the behaviours plugin

Behaviour plugin Version: 0.5.10
JIRA Version 6.0.4 Build Number 6100

I have placed the following in the serverside script box and turned logging on.. however nothing seems to be happeneing when I enter or edit a new bug where Cameras is selected as a component and the Camera field is left empty... I was expecting an error. Any suggestions as to whats missing?

I turned logging on but dont see anything in th log window when I use F12 on the browser.

FormField componentField = getFieldByName("Component/s")
FormField cameraField = getFieldByName("Camera")

if (componentField.getFormValue() == "Cameras")

{

cameraField.setHelpText("<div class=\"warningBox\">As this is a cameras issue you must detail the camera you are using on the 'System' tab.</div>")


cameraField.setRequired(true)

}
else {
cameraField.setRequired(false)
}

Cheers

Nick

4 answers

0 votes
Deepali Bagul August 14, 2019

Hi All,

Just posting an solution link incase someone like me come across this page. The question is answer in the following link

https://community.atlassian.com/t5/Jira-questions/Making-custom-fields-invisible-and-mandatory-based-on-component/qaq-p/131311

Thanks!

0 votes
NickW November 20, 2013

Hi

So got the debug output working... and found this:

[onresolve.jira.groovy.BehaviourManagerImpl] Found class but could not find method run
groovy.lang.MissingPropertyException: No such property: getValue for class: com.onresolve.jira.groovy.user.FormField

which is related to:

if (componentField.getValue*.name.contains("Cameras"))

where

FormField componentField = getFieldByName("Component/s")

the easy question is to ask if someone can help with what is wrong. But also can someone point me to the documentation etc where I can see what methods are in what classes etc.

thanks

0 votes
rambabu patina
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.
November 12, 2013

AFAIK we cannot make a field as required by programatically.

To validate the field values required you can write validation on the field

as if camera is selected as component and cameraField is empty then

addError("cameraField", "This field required value");

Hope this helps you,

Patina

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.
November 11, 2013

Use:

if (componentField.getValue*.name.contains("Cameras"))

(untested)

getFormValues will return a list of component IDs, so your condition will never be true.

> I turned logging on but dont see anything in th log window when I use F12 on the browser.

It logs to atlassian-jira.log. But you should add some logging to your code, eg:

log.debug ("Components are: " + componentField.getValue())

NickW November 12, 2013

Hi Jamie

Thanks for the reply. I have checked atlassian-jira.log but dont see any of my debug output. Deebug is turned on in the behaviours plugin and I have added log.debug messages in various places. It makes me wonder if the serverside script is not being called?

In the behaviours plugin I have put the serverside script on the components field. I made no changes to the Camera field.

Nick

Suggest an answer

Log in or Sign up to answer