My goal is to hide one field (PlatformCategory) based on the value of another field (Product/Component), whereby the PlatformCategory field will only be visible when Product/Component = "Platform". Ideally, this should work correctly on the initial Create Issue screen (field hidden because Product/Component is initially null), as well as on the initial drawing of the Edit Issue screen (field hidden or shown based on the current Product/Component value).
Based on the example documention from Jamie (https://jamieechlin.atlassian.net/wiki/display/JBHV/Miscellaneous+Behaviours+Examples#MiscellaneousBehavioursExamples-Showorhidefields), I originally configured the following:
Create new Behavior:
- Name = Hide Platform Category Programmatically
- Description = Hide the Platform Category field unless Product = Platform
- Add Field "Product/Component"
Add serverside script:
FormField ProductValue = getFieldById ("customfield_11512") // id for Product/Component
FormField PlatformCategoryName = getFieldById ("customfield_11401") // id for PlatformCategory
String producttype = (String) ProductValue.getValue()
if (producttype =~ /12946/) { // id from initial part of Cascading Select "Platform"
PlatformCategoryName.setHidden(false)
}
else {
PlatformCategoryName.setHidden(true)
}
Add Mapping:
- Behaviour ID = Hide Platform Category
- Issue Types = Any issue type
- Projects = All
This seemed to work fine, except that on the initial drawing of the Create Issue screen, the PlatformCategory (that I wanted to be hidden) was initially visible (but would become hidden/unhidden based on Product/Component as desired, once a value was selected in that field).
After playing around a bit, I realized that I could create a separate behavior on the dependent PlatformCategory field, setting the field to hidden, and then allow the server script on Product/Component to drive whether PlatformCategory should be shown or not.
This solves the Create Issue scenario, but breaks the Edit Issue scenario, because the PlatformCategory will always be initially hidden when using Edit Issue, even if the Product/Component is actually "Platform". Basically, it seems that the server script that is attached to the field only gets executed if the user modifies the field value, and only then does the dependent field logic works correctly.. Is there some way to cleanly implement this so that the dependent field is always correctly shown or hidden?
Thanks for any help!