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
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!
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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}")
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.