Hide custom fields based on a custom field value, and also hide based on status/transitions

Dan Hellings November 13, 2017

We are trying to hide custom fields based on one of our custom fields value (team), and also hide custom fields based on the workflow status and transition.

We are using Adaptavist scriptrunner and can do this in two separate behaviours:

1. Hide certain custom fields based on a custom fields value (so each team only see their own custom fields -  some fields are shared)

2. Hide certain custom fields except when they are in certain workflow statuses or transitions.

If we did one of the above behaviours then the behaviour works correctly. However, if we add both behaviours then only Behaviour 1 works. The custom fields are hidden based on a custom fields value, but the custom fields still appear in all statuses/transitions.

Is there anyway to have both of these behaviours working together, possibly using groovy scripting in a single behaviour?

1 answer

0 votes
Joshua Yamdogo @ Adaptavist
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.
November 14, 2017

I think what you are trying to accomplish can be done with behaviours by adding a condition to see which screen the user is on. Here is some sample code to get you started:

You can use the following to apply the behavior to a specific screen to validate input.

if (getFieldScreen().name == "Some Screen Name") { // check user has a certain screen up    def valueToCheck = getFieldByName("testField") // get the field    // get value and do stuff   }

You can use behaviors to modify the visible/required fields on a screen. You can use a scripted transition to limit the behaviour to a particular workflow step, so that it's only applied on the relevant transition screen.

if (getActionName() == "Transfer Ownership") {
    def fieldToHide = getFieldByName("Some custom field I wish to hide")
    def fieldToRequire = getFieldByName("Some custom field I wish to require")
    fieldToHide.setHidden(true)
    fieldToRequire.setRequired(true)
}

See if you can get something working using the code above. 

Suggest an answer

Log in or Sign up to answer