Forums

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

Hide/show custom fields based on the value of Scripted Field using scriptrunner in JIRA DC

Digvijay Singh Gehlot
Contributor
June 3, 2024

Hi Team,

I want to hide/show custom fields based on the value of a Scripted Field using scriptrunner behaviour in JIRA DC.

I have create a Scripted Field which has values as High/ Medium/ Low. Based of these values, I want to hide/show other custom fields for eg:

Scripted Field =High, hide CustomField 1 but show CustomField 2.

Scripted Field = Medium, show CustomField 1 but hide CustomField 2

Scripted Field = Low, hide CustomField 1 and 2

I need help with the groovy script and how to call the value of scripted field using it's ID to make the above behaviour. 

Thanks

1 answer

0 votes
Tuncay Senturk
Community Champion
June 4, 2024

Hi @Digvijay Singh Gehlot 

This is the answer for Jira Datacenter (you asked for DC I suppose, but it was also tagged as cloud).

First, you have to create a new Behavior and map it to the relevant project and/or the issue type. Then, in the Behavior script, you’ll have the logic as written below (sample script below).

Please bear in mind that I wrote the code first here and I haven't tested it in an environment.

 

def scriptedFieldId = // your scripted field's ID such as customfield_11234
def customField1Id = // your customfield 1's id
def customField2Id = // your customfield 2's id

def scriptedField = getFieldById(scriptedFieldId)
def scriptedFieldValue = scriptedField.value

def customField1 = getFieldById(customField1Id)
def customField2 = getFieldById(customField2Id)

if (scriptedFieldValue == 'High') {
    customField1.setHidden(true)
    customField2.setHidden(false)
} else if (scriptedFieldValue == 'Medium') {
    customField1.setHidden(false)
    customField2.setHidden(true)
} else if (scriptedFieldValue == 'Low') {
    customField1.setHidden(true)
    customField2.setHidden(true)
}

 

I hope this helps!

Digvijay Singh Gehlot
Contributor
June 4, 2024

Hi @Tuncay Senturk 

Thank you for your message.

It seems the above code is not reflecting the expected result.

Although, I added the Scripted Field details, but it looks like the system is not picking up the value from the Scripted Field and then it is not performing the behaviour of hide/show of fields on the screen.

I am thinking of a workaround - copy the Scripted Field to a Text field first, and then apply the behaviour based on that text field.

Please suggest further with required screenshots or script, it would be a great help.

Thanks.

 

Tuncay Senturk
Community Champion
June 5, 2024

Hi @Digvijay Singh Gehlot 

No, I don't think it's a good idea to copy its value to another redundant field. Could you please add some logs to the code in various places and trace the value of each? Possible problem is the value of the field is numeric (like 10010, 10011 which may be the option id values of High, Medium and Low).

def scriptedField = getFieldById(scriptedFieldId)
def scriptedFieldValue = scriptedField.value
log.error("The value of scripted field is: ${scriptedFieldValue}")

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
TAGS
AUG Leaders

Atlassian Community Events