Hello - I am trying to show different select list options depending on the custom field value selected. My script is not working, below is the script I am using.
import com.atlassian.jira.component.ComponentAccessor
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def vertical = getFieldById("customField_10433")
def verticalValue = vertical.getValue()
if (vertical == "Retail"){
def retailOptions = optionsManager.getOptions(fieldConfig){
it.name in ["Email", "Audience Workshop", "Audience Plan", "Media Plan", "RFP", "Proactive Audience Outreach", "Campaign Tracker"]
}
else {
def autoOptions = optionsManager.getOptions(fieldConfig){
it.name in ["chevy", "ford", "buick"]
}
getFieldbyId("customfield_12711").setFieldOptions(allowedOptions)
}
}
Hi Ashlee,
There are a few reasons why this script is not working:
1. Your curly braces are misplaced ( these ones -> {} ).
2. You haven't got the field config for the options, so your 'fieldConfig' value that you have passsed to getOptions() will be null.
3. You need to add .FindAll() between your closure and getOptions(method), as you are currently checking for a boolean.
4. You have not assigned anything to the 'allowedOptions' value you are passing to .setFieldOptions() method.
Other tips are:
1. Get the field by name instead of ID, as this accounts for system migrations
2. toString() the vertical value in the if statement so that you are always comparing two of the same object types
The script below has corrected all the issues. It is untested but I believe it should work. Let me know if you have more issues.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
Issue issue = issue
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def vertical = getFieldByName("vertical")
def otherField = getFieldByName("other field")
def otherFieldCustomField = customFieldManager.getCustomFieldObjectByName("other field")
def verticalValue = vertical.getValue()
def fieldConfig = otherFieldCustomField.getRelevantConfig(issue)
def allowedOptions = null
if (verticalValue.toString() == "Retail"){
allowedOptions = optionsManager.getOptions(fieldConfig).findAll{
it.value in ["Email", "Audience Workshop", "Audience Plan", "Media Plan", "RFP", "Proactive Audience Outreach", "Campaign Tracker"]
}
}else {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll{
it.value in ["chevy", "ford", "buick"]
}
}
otherField.setFieldOptions(allowedOptions)
Thanks
Johnson Howard (Adaptavist)
Thanks Johnson, I am still getting a few errors on the actual script and when I run it this is the main error:
java.lang.NullPointerException: Cannot invoke method getFieldIdByName() on null object at com.onresolve.jira.groovy.user.FieldBehaviours.getFieldByName(FieldBehaviours.groovy:69) at Script1025.run(Script1025.groovy:16)
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.component.ComponentAccessor
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.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def vertical = getFieldByName("vertical")
def typeOfEngagement = getFieldByName("type of engagement")
def typeOfEngagementCustomField = customFieldManager.getCustomFieldObjectByName("type of engagement")
def verticalValue = vertical.getValue()
def fieldConfig = typeOfEngagementCustomField.getRelevantConfig(issue)
def allowedOptions = null
if (verticalValue.toString() == "Retail"){
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["Email", "Audience Workshop", "Audience Plan", "Media Plan", "RFP", "Proactive Audience Outreach", "Campaign Tracker",]
}
}else {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["Proactive Audience", "Outreach", "Campaign Tracker"]
}
}
typeOfEngagement.setFieldOptions(allowedOptions)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Are you putting this in as a behaviour?
What do you mean when you are say that you 'run' it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have tried it as both a behaviour and in scriptrunner. The run it was in reference to scriptrunner.
As a behaviour - using a server side script, I get an error on Issue issue = issue stating that issue is undeclared. And an error on the very bottom line: typeOfEngagement.setFieldOptions(allowedOptions) that reads: cannot find matching method
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this as a behaviour mapped to the Vertical Field (Ignore the error on the bottom line, it won't effect the script) :
import com.atlassian.jira.component.ComponentAccessor
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.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def vertical = getFieldByName("vertical")
def typeOfEngagement = getFieldByName("type of engagement")
def typeOfEngagementCustomField = customFieldManager.getCustomFieldObjectByName("type of engagement")
def verticalValue = vertical.getValue()
def fieldConfig = typeOfEngagementCustomField.getRelevantConfig(getIssueContext())
def allowedOptions = null
if (verticalValue.toString() == "Retail"){
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["Email", "Audience Workshop", "Audience Plan", "Media Plan", "RFP", "Proactive Audience Outreach", "Campaign Tracker",]
}
}else {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["Proactive Audience", "Outreach", "Campaign Tracker"]
}
}
typeOfEngagement.setFieldOptions(allowedOptions)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am still getting errors on the:
def verticalValue = issue.getValue(vertical)
error is Cannot find matching method
AND
typeOfEngagement.setFieldOptions(allowedOptions)
error is cannot find matching method
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.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def issue = getUnderlyingIssue();
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def vertical = getFieldById("customfield_10433")
def typeOfEngagement = getFieldById("customfield_12711")
def typeOfEngagementCustomField = customFieldManager.getCustomFieldObjectByName("Type of engagement")
def verticalValue = issue.getValue(vertical)
def fieldConfig = typeOfEngagementCustomField.getRelevantConfig(issue)
def allowedOptions = null
if (verticalValue.toString() == "Retail"){
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["Email", "Audience Workshop", "Audience Plan", "Media Plan", "RFP", "Proactive Audience Outreach", "Campaign Tracker",]
}
}else {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["Proactive Audience", "Outreach", "Campaign Tracker"]
}
}
typeOfEngagement.setFieldOptions(allowedOptions)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ashlee,
The getValue method is not applicable to the Issue object. It is applicable for the FormField object. I have made a couple of changes, the code below has no errors when using an IDE that has the Groovy SDK installed. I have not ran it as I don't know your full configuration. Put this as a behaviour.
I don't know why you removed the getIssueContext() method that I put in? The way you are doing it would mean that there would always have to be an issue underneath the dialog that matched the one you were create/editing. I assume this is not the case, hence why I changed this to getIssueContext() not just issue (line 23).
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.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def issue = getUnderlyingIssue();
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
FormField vertical = getFieldById("customfield_10433")
FormField typeOfEngagement = getFieldById("customfield_12711")
def typeOfEngagementCustomField = customFieldManager.getCustomFieldObjectByName("Type of engagement")
def verticalValue = vertical.getValue()
def fieldConfig = typeOfEngagementCustomField.getRelevantConfig(getIssueContext())
def allowedOptions = null
if (verticalValue.toString() == "Retail"){
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["Email", "Audience Workshop", "Audience Plan", "Media Plan", "RFP", "Proactive Audience Outreach", "Campaign Tracker",]
}
}else {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["Proactive Audience", "Outreach", "Campaign Tracker"]
}
}
typeOfEngagement.setFieldOptions(allowedOptions)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have tried the above script in Behavior. I have modified the script according to my requirement.
My actual requirement is need to change select list based on the Component/s field value.
We are using JIRA server with version v8.2.4.
I am getting error "unable to resolve class com.atlassian.jira.ComponentManager"
Can you please help me to sort out the issue.
Below is the code I modified according to my requirement.
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.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def issue = getUnderlyingIssue();
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
FormField component = getFieldById("Component/s")
FormField applicationx = getFieldById("customfield_17357")
def applicationxCustomField = customFieldManager.getCustomFieldObjectByName("Applicationx")
def componentvalue = component.getValue()
def fieldConfig = applicationxtCustomField.getRelevantConfig(getIssueContext())
def allowedOptions = null
if (componentValue.toString() == "AO Docs") {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["On/Off Boarding", "PPWA", "LRM", "Email", "Libraries/Generic"]
}
}
else if (componentValue.toString() == "Zucchetti") {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["HR Infinity", "Mobile App", "Asset Management"]
}
}
else if (componentValue.toString() == "LMS") {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["Discovery", "Elucidat", "Userlane"]
}
}
else if (componentValue.toString() == "Others") {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["Workplace", "Org. Chart"]
}
}
else {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["On/Off Boarding", "PPWA", "LRM", "Email", "Libraries/Generic", "HR Infinity", "Mobile App", "Asset Management", "Discovery", "Elucidat", "Userlane", "Workplace", "Org. Chart"]
}
}
applicationx.setFieldOptions(allowedOptions)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Johnson,
I have a requirement of display only options in single select drop down field based on the value selected in Component/s Field.
I came across the script you have mentioned and modified according to my requirement.
But unfortunately I am getting an error stating "unable to resolve class com.atlassian.jira.ComponentManager".
We are currently using JIRA server v8.2.4
Below code is modified according to my requirement.
Can you help me to fix the issue I am facing,
Thanks,
Vasanta
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.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def issue = getUnderlyingIssue();
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
FormField component = getFieldById("Component/s")
FormField applicationx = getFieldById("customfield_17357")
def applicationxCustomField = customFieldManager.getCustomFieldObjectByName("Applicationx")
def componentvalue = component.getValue()
def fieldConfig = applicationxtCustomField.getRelevantConfig(getIssueContext())
def allowedOptions = null
if (componentValue.toString() == "AO Docs") {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["On/Off Boarding", "PPWA", "LRM", "Email", "Libraries/Generic"]
}
}
else if (componentValue.toString() == "Zucchetti") {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["HR Infinity", "Mobile App", "Asset Management"]
}
}
else if (componentValue.toString() == "LMS") {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["Discovery", "Elucidat", "Userlane"]
}
}
else if (componentValue.toString() == "Others") {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["Workplace", "Org. Chart"]
}
}
else {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["On/Off Boarding", "PPWA", "LRM", "Email", "Libraries/Generic", "HR Infinity", "Mobile App", "Asset Management", "Discovery", "Elucidat", "Userlane", "Workplace", "Org. Chart"]
}
}
applicationx.setFieldOptions(allowedOptions)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vasanta,
You should just be able to remove this line:
import com.atlassian.jira.ComponentManager
Then it should work.
Thanks
Johnson
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, Johnson,
I have removed the line as you suggested but now I am receiving a error in the above code, below is the screen shot.
Can you suggest How to resolve the issue.
Thanks,
Vasanta
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have just pasted this into my Jira console and go no errors:
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.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.ComponentAccessor
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def issue = getUnderlyingIssue();
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
FormField component = getFieldById("Component/s")
FormField applicationx = getFieldById("customfield_17357")
def applicationxCustomField = customFieldManager.getCustomFieldObjectByName("Applicationx")
def componentValue = component.getValue()
def fieldConfig = applicationxCustomField.getRelevantConfig(getIssueContext())
def allowedOptions = null
if (componentValue.toString() == "AO Docs") {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["On/Off Boarding", "PPWA", "LRM", "Email", "Libraries/Generic"]
}
}
else if (componentValue.toString() == "Zucchetti") {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["HR Infinity", "Mobile App", "Asset Management"]
}
}
else if (componentValue.toString() == "LMS") {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["Discovery", "Elucidat", "Userlane"]
}
}
else if (componentValue.toString() == "Others") {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["Workplace", "Org. Chart"]
}
}
else {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["On/Off Boarding", "PPWA", "LRM", "Email", "Libraries/Generic", "HR Infinity", "Mobile App", "Asset Management", "Discovery", "Elucidat", "Userlane", "Workplace", "Org. Chart"]
}
}
applicationx.setFieldOptions(allowedOptions)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Johnson,
I used the above script in Behaviours. Now I am not getting any errors and getting only a warning message. "Use CustomFieldManager.getCustomFieldObjectByName("string") instead. line 19 & line 31".
I have configured the script under Behaviour settings under fields Component/s.
I tried to check after saving it but if I select the option in Component/s field and when I check the drop down field applicationx I can see all the list.
What can be the issue or how to use it with Adaptive script runner to work.
I am New to JIRA, so can you please help me out.
Thanks,
Vasanta
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It could be that you are requesting the components/ custom field by id but giving it a name instead. Like so:
FormField component = getFieldById("Component/s")
FormField applicationx = getFieldById("customfield_17357")
See my example below:
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.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def issue = getUnderlyingIssue();
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
FormField vertical = getFieldById("customfield_10433")
FormField typeOfEngagement = getFieldById("customfield_12711")
def typeOfEngagementCustomField = customFieldManager.getCustomFieldObjectByName("Type of engagement")
def verticalValue = vertical.getValue()
def fieldConfig = typeOfEngagementCustomField.getRelevantConfig(getIssueContext())
def allowedOptions = null
if (verticalValue.toString() == "Retail"){
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["Email", "Audience Workshop", "Audience Plan", "Media Plan", "RFP", "Proactive Audience Outreach", "Campaign Tracker",]
}
}else {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["Proactive Audience", "Outreach", "Campaign Tracker"]
}
}
typeOfEngagement.setFieldOptions(allowedOptions)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@JohnsonHoward how to find it.value NOT in? in a collection. or with in find all how to set not to show none
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ashlee,
The code used for getting the custom field value is wrong.
Try the below code
def cf = customFieldManager.getCustomFieldObjectById("customfield_10433")
def verticalValue =issue.getCustomFieldValue(cf)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
And the code for setting the options is also wrong, pleas refer the below links for more information.
-Praveen
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Praveen,
The code you have suggested above will only work if the issue already exists and if the vertical custom field already has a value. So your suggestion wouldn't work if this script is to run when creating an issue. I assume that Ashlee wants to get the value of the vertical custom field when the user interacts with the custom field on the form. Therefore you need to use :
def vertical = getFieldById("customfield_10433")
def verticalValue = vertical.getValue()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No problem Praveen. It's something that always trips people up.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Johnson,
I am still getting errors on the if else statement, more specifically it says allowedOptions is undeclared and the variable field config is undeclared when passed as argument after optionsManager.getOptions(fieldConfig).findAll
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.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.issue.customfields.manager.OptionsManager
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 vertticalValue = vertical.getValue()
def typeOfEngagement = getFieldByName("type of engagement")
def typeOfEngagementCustomField = customFieldManager.getCustomFieldObjectByName("Type of Engagement")
def optionAuto = ["Proactive Audience", "Outreach", "Campaign Tracker"]
def optionRetail = ["Email", "Audience Workshop", "Audience Plan", "Media Plan", "RFP", "Proactive Audience Outreach", "Campaign Tracker"]
if (vertical.toString() == "Retail"){
allowedOptions = optionsManager.getOptions(fieldConfig).findAll {
it.value in ["Email", "Audience Workshop", "Audience Plan", "Media Plan", "RFP", "Proactive Audience Outreach", "Campaign Tracker", "Email"]
}
}else {
allowedOptions = optionsManager.getOptions(fieldConfig).findall {
it.value in ["Audience Planning", "Demographic Profiling", "Audience Matrix", "RFP", "Email"]
}
}
typeOfEngagement.setFieldOptions(allowedOptions)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ashlee,
It seems again that you have removed a critical part of the code that I shared with you.
You need to add this into your variables:
def allowedOptions = null
Try this and let me know
Thanks
Johnson Howard (Adaptavist)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hopefully almost there, now I am getting an error on the very last line: typeOfEngagement.setFieldOptions(allowedOptions) - the errors says: cannot find matching method setFieldOptions
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 allowedOptions = null
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def fieldConfig = CustomField.getRelevantConfig(issueContext)
def vertical = getFieldByName("vertical")
def vertticalValue = vertical.getValue()
def typeOfEngagement = getFieldByName("type of engagement")
def typeOfEngagementCustomField = customFieldManager.getCustomFieldObjectByName("Type of Engagement")
def optionAuto = ["Proactive Audience", "Outreach", "Campaign Tracker"]
def optionRetail = ["Email", "Audience Workshop", "Audience Plan", "Media Plan", "RFP", "Proactive Audience Outreach", "Campaign Tracker"]
if (vertical.toString() == "Retail"){
allowedOptions = optionsManager.getOptions(fieldConfig).findAll() {
it.value in ["Email", "Audience Workshop", "Audience Plan", "Media Plan", "RFP", "Proactive Audience Outreach", "Campaign Tracker", "Email"]
}
}else {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll() {
it.value in ["Audience Planning", "Demographic Profiling", "Audience Matrix", "RFP", "Email"]
}
}
typeOfEngagement.setFieldOptions(allowedOptions)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ashlee,
Some other things that you have changed will cause this script not to work.
You have CustomField.geRelevantConfig(issueContext) - this is incorrect, you need to get the config the custom field that you are trying to set the options which is Type of Engagement.
Also you have vertical.toString() instead of verticalValue.toString(), so you are converting the object to a string not the value.
Try this:
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 allowedOptions = null
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def typeofEngagementCustomField = customFieldManager.getCustomFieldObjectByName("Type of Engagement")
def fieldConfig = typeofEngagementCustomField.getRelevantConfig(issueContext)
def vertical = getFieldByName("vertical")
def verticalValue = vertical.getValue()
def typeOfEngagement = getFieldByName("type of engagement")
if (verticalValue.toString() == "Retail"){
allowedOptions = optionsManager.getOptions(fieldConfig).findAll() {
it.value in ["Email", "Audience Workshop", "Audience Plan", "Media Plan", "RFP", "Proactive Audience Outreach", "Campaign Tracker", "Email"]
}
}else {
allowedOptions = optionsManager.getOptions(fieldConfig).findAll() {
it.value in ["Audience Planning", "Demographic Profiling", "Audience Matrix", "RFP", "Email"]
}
}
typeOfEngagement.setFieldOptions(allowedOptions)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Johnson,
Great, so no errors but the code isn't working. I have it as a server side script and have tried it on both the Type of Engagement Field and the Vertical field...any thoughts?
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 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 optionAuto = ["Proactive Audience", "Outreach", "Campaign Tracker"]
def optionRetail = ["Email", "Audience Workshop", "Audience Plan", "Media Plan", "RFP", "Proactive Audience Outreach", "Campaign Tracker"]
if (verticalValue.toString() == "Retail"){
allowedOptions = optionsManager.getOptions(fieldConfig).findAll() {
it.value in ["Email", "Audience Workshop", "Audience Plan", "Media Plan", "RFP", "Proactive Audience Outreach", "Campaign Tracker", "Email"]
}
}else {
allowedOptions = optionsManager.getOptions(fieldConfig).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.
Why has this line been removed?
typeOfEngagement.setFieldOptions(allowedOptions)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can ignore that error as it shouldnt have an effect on runtime.
But if you really want it to go away you can do this at the bottom:
if(allowedOptions){
typeOfEngagement.setFieldOptions(allowedOptions as List<Option>)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Johnson - so the code below works but for some reason it doesn't pull the list in the order listed...any ideas?
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 verticalCustomField = getFieldByName("Vertical")
def verticalValue = verticalCustomField.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"]
})
}else {
allowedOptions = typeOfEngagement.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 could trying using .sort() to help sort your options.
If the code is working could you please mark one of my above answers as accepted.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Johnson - one last question - I am trying to list multiple fields either either with additional if or &&. They are not dependent on one another but they are all dependent on the variable field. See code below:
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 customField = customFieldManager.getCustomFieldObjectByName("Type of Engagement")
def customFieldCRO = customFieldManager.getCustomFieldObjectByName("Campaign Type")
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
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"]}
if (verticalValue.toString() == "Retail") {
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(optionsCRO.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.
Does this work?
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 customField = customFieldManager.getCustomFieldObjectByName("Type of Engagement")
def customFieldCRO = customFieldManager.getCustomFieldObjectByName("Campaign Type")
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
def configCRO = customFieldCRO.getRelevantConfig(getIssueContext())
def optionsCRO = optionsManager.getOptions(config)
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"]
})
}
if (verticalValue.toString() == "Retail") {
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(optionsCRO.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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi - here is the error: java.lang.NullPointerException: Cannot invoke method getFieldIdByName() on null object at com.onresolve.jira.groovy.user.FieldBehaviours.getFieldByName(FieldBehaviours.groovy:69) at Script1025.run(Script1025.groovy:16)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.