Behavior Plugin - Setting a custom date picker field to be required if certain value was chosen in radio buttons custom field

Eitan Gur March 13, 2016

Hi All,

I'm trying to set a date picker custom field to be required if certain value in another custom field (radio buttons) was chosen.

Tried with no success:

def InstallDate = getFieldByName("Installation Date")
def InstallStatus = getFieldById(getFieldChanged())
def selectedOption = InstallStatus.getValue() as String
def isInstallSelected = selectedOption == "Certain Value"
InstallDate.setHidden(! isInstallSelected)
InstallDate.setRequired(isInstallSelected)

And:

def installStatusRadioButtons = getFieldByName("Installation Status")
def installDatePicker = getFieldByName(getFieldChanged())
 
def installStatusRadioButtonsValue = installStatusRadioButtons.getValue()
 
if(installStatusRadioButtonsValue == "Certain Value"){
    formField.setRequired(true)}

Also I'll be glad for some clarification what should I use:

Fields
Initialiser Function

Or 

Add Field

Add one or more fields to this Behaviour.

Maybe configure some general settings in a certain way?

 

Thank you in advance!

1 answer

1 accepted

1 vote
Answer accepted
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 4, 2016

Hi Eitan,

In order to answer your questions above you should use the Add Field option in order to configure the behaviour on a particular custom field. You can find more information on how to configure Behaviours here.

Also I have attached below a sample script along with its config that will allow you to make a custom date picker field required based on the value of a radio button.

This code was developed and tested on JIRA 6.4.12 using ScriptRunner 4.1.3.10.

Code:

 

// Get pointers to my fields
def radiocf = getFieldByName("Installation Status")
def datecf = getFieldByName("Installation Date") 

// Get the radio buttons value
String radioCfVal = radiocf.getValue()

// If option A is selected in the Installation Status radio buttons 
// then make Installation Daterequired else make it optional.
if(radioCfVal == "A"){
    datecf.setRequired(true)
}else{
    datecf.setRequired(false)
}

Config:

image2016-4-4 15:56:55.png

I hope this helps

Kristian

Eitan Gur April 7, 2016

Kristian, thank you for the great answer! Works like a charm.

 

Just an additional question if you're able to advise-

The date field becomes required only when going to "Edit" option in the issue and prevents from leaving the screen as expected.

However, the condition field ("Installation Status") is editable also in the default screen. There, if I'm picking the "A" option - nothing happens. Apparently because the date field doesn't appear on the default screen until being edited and populated with any value.

 

Do you have any proposals how can I condition this behavior to happen on the default screen also?

 

Thank you

Eitan

 

 

 

Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 7, 2016

HI Eitan,

Behaviours only happen on the create and edit screen.  The fields would need to be available on both screens in order for the behaviour to work.

I hope this helps.

Kristian

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events