Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Making one field OR a second field required with Scriptrunner Behaviour

Marco Brundel
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.
May 30, 2023

Hi,
using a Scriptrunner Behavior I want to check on a Jira Service Management Request type whether issue-picker field (Field A) OR a URL field (Field B) is filled by the customer.

Fields A OR B must therefore be filled at least.

Does anyone have any suggestions on what the script should look like?

Regards, Marco Brundel

2 answers

1 accepted

0 votes
Answer accepted
Ram Kumar Aravindakshan _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.
May 30, 2023

Hi @Marco Brundel

For your requirement, you should use ScriptRunner' Behaviour. You can try something like this:-

For the first field, i.e. the text field:-

def sampleText = getFieldById(fieldChanged)
def sampleTextValue = sampleText.value.toString()

def ipName = getFieldByName('IP Name')
def ipNameValue = ipName.value

sampleText.required = true
ipName.required = true

sampleText.clearError()
ipName.clearError()

if (!sampleTextValue && !ipNameValue) {
sampleText.setError('Either Sample Text of IP Name should be filled')
ipName.setError('Either Sample Text of IP Name should be filled')
}

if (sampleTextValue) {
ipName.required = false
}

if (ipNameValue) {
sampleText.required = false
}

For the second field, i.e. the issue picker:-

def ipName = getFieldById(fieldChanged)
def ipNameValue = ipName.value

def sampleText = getFieldByName('Sample Text')
def sampleTextValue = sampleText.value.toString()

sampleText.required = true
ipName.required = true

sampleText.clearError()
ipName.clearError()

if (!sampleTextValue && !ipNameValue) {
sampleText.setError('Either Sample Text of IP Name should be filled')
ipName.setError('Either Sample Text of IP Name should be filled')
}

if (sampleTextValue) {
ipName.required = false
}

if (ipNameValue) {
sampleText.required = false
}

Please note that the sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below is a screenshot of the Behaviour configuration:-

behaviour_config-1.png

Basically, what the Behaviour configuration above does is that if fields A and B are not filled, it will display a field error on both fields. If either one of the fields is filled, the error message is removed, and the 2nd field that is not yet filled will become optional.

I hope this helps to solve your question. :-)

Thank you and Kind regards,

Ram

0 votes
Graham Twine
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.
May 30, 2023

Hello @Marco Brundel ,

 

In the event that someone is clearing out a field then the following need to hold true.

In Field A one needs to consider the value in field B.

Likewise field B needs to consider field A.

 

Field A & Field B server side script

def a = getFieldByName('A').value
def b = getFieldByName('B').value

def fieldC = getFieldByName('C')

if(a || b) {
fieldC.setHidden(false)

} else {
fieldC.setHidden(true)
}

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events