Forums

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

How can I check in a behaviour script that the "Affects version/s" field is empty?

Gergely Fehér
Contributor
April 9, 2020 edited

I have an "Affects Branch/es" custom field, and I'd like to force to have only one of "Affects version/s" and "Affects Branch/es" filled - in our system filling none or both is invalid.

A tried the following code, but it does not work:

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

def branchesField = getFieldByName("Affects Branch/es")
def branchesFieldStringValue = branchesField.getValue()

def versionsField = getFieldById("versions")
def versionsFieldStringValue = versionsField.getValue()

if (branchesFieldStringValue == null && versionsFieldStringValue == null) {
branchesField.setError("brancherror both empty 3")
}

if (branchesFieldStringValue != null && versionsFieldStringValue != null) {
branchesField.setError("brancherror both filled 4")
}


I think the problem is the way I checked if they're empty or not. I tried with converting them with .tostring() and comparing with "" and some other ways - but now I think I'm getting lost. Can someone help me?

1 answer

1 accepted

1 vote
Answer accepted
SITTER Adrien
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.
April 10, 2020

Hello @Gergely Fehér

 

This is a Groovy script. Groovy is made to simplify this kind of things.

Try this:

if (branchesFieldStringValue && versionsFieldStringValue) {
branchesField.setError("branchesboth empty 3")
}

if (!branchesFieldStringValue && !versionsFieldStringValue) {
branchesField.setError("brancherror both filled 4")
}

 Regards,

 

Adrien

Gergely Fehér
Contributor
April 12, 2020

Hi @SITTER Adrien,

Thanks a lot, it works!

Siva Indukuri
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 28, 2020

I wrote the below code in behaviour script to check if the field is empty . It is working if it is empty.. however, If i enter something the error is not cleared. Please help ,

I need to clear the error message if there is something in the field.

def loc=getFieldById("customfield_10612")
if (loc) {
loc.setError("Please Enter loc")
}

Siva Indukuri
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 28, 2020

How do we check if the given field value is text or not in behaviour script in jira

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, loom, loom for training, loom for teaching, video training, async learning, online education, screen recording, loom tutorials, loom use cases, atlassian learning, team training tools, instructional video, virtual training tools

🛗 Elevate Your Training and Enablement with Loom

Join us June 26, 11am PT for a webinar with Atlassian Champion Robert Hean & Loom’s Brittany Soinski. Hear tips, stories, and get your burning questions answered. Learn how Loom makes training and enablement easier. Don’t miss it!

Register today
AUG Leaders

Atlassian Community Events