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
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:-
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
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)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.