Help! I am trying to hide and show certain fields in a single select drop down list if a different custom field value = retail.
Here is the code that isn't working:
import com.atlassian.jira.ComponentAccessor
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.config.FieldConfigImpl
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def vertical = getFieldByName("vertical")
def verticalValue = vertical.getValue() as String
def typeOfEngagement = getFieldByName("type of engagement")
def typeOfEngagementCustomField = customFieldManager.getCustomFieldObjectByName("Type of Engagement")
def typeOfEngagementAp = customFieldManager.getCustomFieldObjectByName("Type of Engagement(Demographic Profiling)")
def fieldConfig = typeOfEngagementCustomField.getRelevantConfig(issueContext)
def isVerticalRetail = verticalValue == "Retail"
if (! isVerticalRetail){
typeOfEngagementAp.setHidden(true)
} else {
typeOfEngagementAp.setHidden(false)
}
Are there any errors in the atlassian-jira.log file?
It should be like this
def vertical = getFieldByName("vertical")
log.error("vertical: " + vertical)
def verticalValue = vertical.getValue() as String
log.error("verticalValue: " + verticalValue)
def typeOfEngagement = getFieldByName("type of engagement")
log.error("typeOfEngagement: " + typeOfEngagement)
def isVerticalRetail = verticalValue == "Retail"
if (! isVerticalRetail){
typeOfEngagement.setHidden(true)
} else {
typeOfEngagement.setHidden(false)
}
Also make sure that your field names are correct. getFIeldByName is case sensitive. Have a look in the log file to see the output
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just to clarify, I am trying to hide selection options within the Type of Engagement field but not hide the entire field. I am trying to hide it on the create screen after the vertical field is selected and based on the value entered into that field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
then you should use setFieldOptions instead of setHidden. You can find an example here:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok - I'm getting an error on formfield: the variable is undeclared. How do you declare formfield - I can't find it in the docs.
import com.atlassian.jira.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.config.FieldConfigImpl
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def allowedOptions = null
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def vertical = getFieldByName("vertical")
def verticalValue = vertical.getValue()
def typeOfEngagement = getFieldByName("type of engagement")
def typeOfEngagementCustomField = customFieldManager.getCustomFieldObjectByName("Type of Engagement")
def fieldConfig = typeOfEngagementCustomField.getRelevantConfig(issueContext)
def customField = customFieldManager.getCustomFieldObject(getFieldChanged())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
if (verticalValue.toString() == "Retail"){
allowedOptions = formField.setFieldOptions(options.findAll {
it.value in ["Email", "Audience Workshop", "Audience Plan", "Media Plan", "RFP", "Proactive Audience Outreach", "Campaign Tracker", "Email"]
})
}else {
allowedOptions = formField.setFieldOptions(options.findAll {
it.value in ["Audience Planning", "Demographic Profiling", "Audience Matrix", "RFP", "Email"]
})
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You have to attach the script to the vertical field, which means that getFieldChanged() returns a reference to the vertical field. That is why your code should look like this:
def allowedOptions = null
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def vertical = getFieldByName("vertical")
def verticalValue = vertical.getValue()
def typeOfEngagement = getFieldByName("type of engagement")
def customField = customFieldManager.getCustomFieldObjectByName("Type of Engagement")
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
if (verticalValue.toString() == "Retail"){
allowedOptions = typeOfEngagement.setFieldOptions(options.findAll {
it.value in ["Email", "Audience Workshop", "Audience Plan", "Media Plan", "RFP", "Proactive Audience Outreach", "Campaign Tracker", "Email"]
})
}else {
allowedOptions = typeOfEngagement.setFieldOptions(options.findAll {
it.value in ["Audience Planning", "Demographic Profiling", "Audience Matrix", "RFP", "Email"]
})
}
Put logging there and make sure you provide valid names for your custom field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks - I have updated the code and there are no errors but it doesn't actually work when I start to create a ticket. It is suppose to change the dropdown options directly after the vertical custom field is selected. Currently, I have all the options in the dropdown list.
import com.atlassian.jira.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.config.FieldConfigImpl
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def allowedOptions = null
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def vertical = getFieldByName("vertical")
def verticalValue = vertical.getValue()
def typeOfEngagement = getFieldByName("type of engagement")
def typeOfEngagementCustomField = customFieldManager.getCustomFieldObjectByName("Type of Engagement")
def fieldConfig = typeOfEngagementCustomField.getRelevantConfig(issueContext)
def customField = customFieldManager.getCustomFieldObjectByName("Type of Engagement")
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
if (verticalValue.toString() == "Retail"){
allowedOptions = typeOfEngagement.setFieldOptions(options.findAll {
it.value in ["Email", "Audience Workshop", "Audience Plan", "Media Plan", "RFP", "Proactive Audience Outreach", "Campaign Tracker", "Email"]
})
}else {
allowedOptions = typeOfEngagement.setFieldOptions(options.findAll {
it.value in ["Audience Planning", "Demographic Profiling", "Audience Matrix", "RFP", "Email"]
})
}
re
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I still strongly believe that you provided wrong names for fields. You should put logging in your script and have a look what is going wrong.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You add logging by log.error. That is the simplest one. You do not have to set logging levels. For example, if you want to see the verticalValue value then you can do like this:
def allowedOptions = null
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def vertical = getFieldByName("vertical")
def verticalValue = vertical.getValue()
def typeOfEngagement = getFieldByName("type of engagement")
def typeOfEngagementCustomField = customFieldManager.getCustomFieldObjectByName("Type of Engagement")
def fieldConfig = typeOfEngagementCustomField.getRelevantConfig(issueContext)
def customField = customFieldManager.getCustomFieldObjectByName("Type of Engagement")
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
log.error("verticalValue: " + verticalValue)
if (verticalValue.toString() == "Retail"){
allowedOptions = typeOfEngagement.setFieldOptions(options.findAll {
it.value in ["Email", "Audience Workshop", "Audience Plan", "Media Plan", "RFP", "Proactive Audience Outreach", "Campaign Tracker", "Email"]
})
}else {
allowedOptions = typeOfEngagement.setFieldOptions(options.findAll {
it.value in ["Audience Planning", "Demographic Profiling", "Audience Matrix", "RFP", "Email"]
})
}
You can see the output in the atlassian-jira.log file.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.jira.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.config.FieldConfigImpl
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def allowedOptions = null
def campaignRetailOptions = null
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def verticalCustomField = getFieldByName("Vertical")
def verticalValue = verticalCustomField.getValue()
def typeOfEngagement = getFieldByName("Type of Engagement")
def typeOfEngagementCustomField = customFieldManager.getCustomFieldObjectByName("Type of Engagement")
def campaignType = getFieldByName("Campaign Type")
def campaignTypeCustomField = customFieldManager.getCustomFieldObjectByName("Campaign Type")
def fieldConfig = typeOfEngagementCustomField.getRelevantConfig(issueContext)
def fieldConfigCRO = campaignTypeCustomField.getRelevantConfig(issueContext)
def customField = customFieldManager.getCustomFieldObjectByName("Type of Engagement")
def customFieldCRO = customFieldManager.getCustomFieldObjectByName("Campaign Type")
def config = customField.getRelevantConfig(getIssueContext())
def configCRO = customFieldCRO.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
def optionsCRO = optionsManager.getOptions(configCRO)
if (verticalValue.toString() == "Retail"){
allowedOptions = typeOfEngagement.setFieldOptions(options.findAll {
it.value in ["Audience Planning", "Audience Workshop", "Campaign Tracker", "Email", "Media Plan", "Proactive Audience Outreach", "RFP"]});
campaignRetailOptions = campaignType.setFieldOptions(options.findAll {
it.value in ["Awareness", "New Store Opening", "Sales Event", "In Market", "Prospecting", "Retention"]})
}else {
allowedOptions = typeOfEngagement.setFieldOptions(options.findAll {
it.value in ["Audience Planning", "Audience Matrix", "Demographic Profiling", "Email", "RFP"]});
campaignRetailOptions = campaignType.setFieldOptions(options.findAll {
it.value in ["Awareness", "Launch", "Sales Event", "In Market"]
})
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alexey - the code is working now but I need to add additional fields in the if/else statement - do I do this with additional ifs even though they aren't dependent on each other or with an &&? Neither option works for me, both just create an empty drop down list.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can do it with the same ifs like you did in the code above.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @bSte i need your help, as i have a requirement same type like yours.
i have a field that has some options, i need to hide some options to user on based upon other customer field value.
how ot show specific 2 or 3 options if field1 has some value?
Regards
Manas
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.