Forums

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

Way to make one field required based on another field selection using scriptrunner behaviors

Joe Harmon
Contributor
April 25, 2023

I have a required field called "Release Type" and when it is set to "Hardware" I want to have the SKU(s) field required.  When it is set to anything else, I want the SKU(s) field optional and read only or if possible hidden.  Here is the script I have so far but it isn't working at all.  I also want the asterisk to show against skus as well if possible.

 

def releaseTypeField = getFieldById(getFieldChanged())

def releaseTypeStatus = releaseTypeField.getValue()

def skusField = getFieldById("SKU(s)")

if (releaseTypeStatus == "Hardware") {
    skusField.setRequired(true) //Sets the SKUs field to required.
    skusField.setHelpText("The SKUs field is required when it is a hardware project")
}
else {
    skusField.setRequired(false) //Sets the SKUs field back to optional
    skusField.setReadOnly(true)
    skusField.setHelpText("")
}

 

1 answer

1 accepted

4 votes
Answer accepted
Mark Markov
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 Champions.
June 8, 2018

Hello @Edward Greathouse

You need create it in your workflow.

Go to workflows -> Choose your workflow, edit -> Choose transition -> Validators -> Add validator -> Script validator

And here you are :)

Suggest an answer

Log in or Sign up to answer