Forums

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

How to make a field read only based on another custom field value

Liat Yanco April 30, 2020

Hi,

 

how can I make a field read-only based on another custom field value?

 

For example, I have 2 custom fields: "reviewed" and "effort".

I want the following:

when "reviewed" is empty, "effort" field is editable

when "reviewed" is non-empty, the "effort" field is a read-only field.

 

I believe it can be done by using behaviors but not sure how :(

 

thanks!

1 answer

1 accepted

0 votes
Answer accepted
Sebastian Krzewiński
Community Champion
May 1, 2020

Hi @Liat Yanco 

 

Please check https://library.adaptavist.com/ There you can find a lot of examples and scripts ready to use.

I think this script will be helpfull :) https://library.adaptavist.com/entity/set-behaviour-read-only

Regards

Seba

Liat Yanco May 1, 2020

Thanks for this @Sebastian Krzewiński !

but I want to base the read-only option with a condition - that another custom field is empty or non-empty:

 

when "reviewed" is empty, "effort" field is editable

when "reviewed" is non-empty, the "effort" field is a read-only field

 

in the example you attached, it is to make the field read-only with no condition.

 

any other idea? :)

Sebastian Krzewiński
Community Champion
May 1, 2020

You can check other scripts and figure out how to do this :)

I didn't test it but please check this code:

import com.atlassian.jira.issue.IssueFieldConstants
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

def effortField = getFieldByName("Effort_Name")
def reviewedField = getFieldByName("Reviewed Name")

if (effortField.getValue()) {
reviewedField.setReadOnly(true)
}
Liat Yanco May 2, 2020

I tried the above and i'm getting the below error:

"Parsing XML failed: Content is not allowed in prolog."

Sebastian Krzewiński
Community Champion
May 3, 2020

Where you got this error?

Liat Yanco May 4, 2020

here in the 'behavior':

I copied your suggestion and got the error: "Parsing XML failed: Content is not allowed in prolog."

Behaviours.png

Sebastian Krzewiński
Community Champion
May 4, 2020

Pleade write steps how you get view from the screenshot.

Liat Yanco May 4, 2020

I'm working on Jira server V6.4.

Jira administration --> add-ons --> Behaviours --> created a new Behaviours --> click Edit in the line of the new behavior that was just created

Sebastian Krzewiński
Community Champion
May 4, 2020

Based on https://scriptrunner.adaptavist.com/4.3.19/jira/behaviours-overview.html try to add code above in inline script section.

Liat Yanco May 8, 2020

OK, so you were right.

it is working!!

 

thank you so much for your help and support :)

Like Sebastian Krzewiński likes this
Gilad Shtern
Contributor
September 13, 2021

Hi @Sebastian Krzewiński ,

 

It seems like this doesn't work well at scriptrunner ver 6.0.2-p5

JIRA ver 8.7.1

Kindly,

Gilad

Suggest an answer

Log in or Sign up to answer