Hi There,
I'm trying to restrict the list of options available under the system field "Priority" but so far no luck. Anyone know how to make this work
Here is my code that's not working yet
import com.atlassian.jira.component.ComponentAccessor import static com.atlassian.jira.issue.IssueFieldConstants.* def customFieldManager = ComponentAccessor.getCustomFieldManager() def optionsManager = ComponentAccessor.getOptionsManager() def formField = getFieldById(PRIORITY) // def customField = customFieldManager.getCustomFieldObject(formField.getFieldId()) def config = customField.getRelevantConfig(getIssueContext()) def options = optionsManager.getOptions(config) def optionsMap = options.findAll { it.value in ["High", "Medium"] // list of options you want to show}.collectEntries { [ (it.optionId.toString()) : it.value ] } // or to show the first 12 options//def optionsMap = options.take(12).collectEntries {// [// (it.optionId.toString()) : it.value// ]//} formField.setFieldOptions(optionsMap)
Are you sure that your code is executed? Can you see any errors?
Thanks @Alexey Matveev for looking into this, I have checked the logs and there is nothing in there.
I'm wondering if it's failing due to this
def config = customField.getRelevantConfig(getIssueContext()) def options = optionsManager.getOptions(config)
since it's not custom field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry was executing something else, here is what I see after enabling "debug"
user: xxxxxx, fieldId: priority, file: <inline script>
java.lang.NullPointerException: Cannot invoke method getRelevantConfig() on null object
at Script1.run(Script1.groovy:11)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The problem is that you use the customField variable but it is not initialized and that is why equals to null. The initialization of the variable is commmented in your script. Kindly uncomment it.
import com.atlassian.jira.component.ComponentAccessor import static com.atlassian.jira.issue.IssueFieldConstants.* def customFieldManager = ComponentAccessor.getCustomFieldManager() def optionsManager = ComponentAccessor.getOptionsManager() def formField = getFieldById(PRIORITY)
def customField = customFieldManager.getCustomFieldObject(formField.getFieldId()) def config = customField.getRelevantConfig(getIssueContext()) def options = optionsManager.getOptions(config) def optionsMap = options.findAll { it.value in ["High", "Medium"] // list of options you want to show}.collectEntries { [ (it.optionId.toString()) : it.value ] } // or to show the first 12 options//def optionsMap = options.take(12).collectEntries {// [// (it.optionId.toString()) : it.value// ]//} formField.setFieldOptions(optionsMap)
But I think it is better if you follow the guide in Scriptrunner (there is an example how to restrict priorities):
import com.atlassian.jira.component.ComponentAccessor
import static com.atlassian.jira.issue.IssueFieldConstants.*
def formField = getFieldById(PRIORITY)
def optionsMap = ComponentAccessor.getConstantsManager().getPriorityObjects().findAll { priority ->
priority.getName() in ["High", "Medium"]
}.collectEntries {
[(it.id): it.name]
}
formField.setFieldOptions(optionsMap)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @Alexey Matveev , I'm sorry it was indeed a bad copy/paste earlier. On my side, it was indeed uncommented. Sorry for that confusion.
BTW when I tried that example, it complains about an deprecated function "getPriorityObjects()" and hence was using that other route.
Hope that clarifies and once again any help in this matter would be greatly appreciated.
Thanks,
Madhu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @Alexey Matveev , I'm sorry it was indeed a bad copy/paste earlier. On my side, it was indeed uncommented. Sorry for that confusion.
BTW when I tried that example, it complains about an deprecated function "getPriorityObjects()" and hence was using that other route.
Hope that clarifies and once again any help in this matter would be greatly appreciated.
Thanks,
Madhu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok. Try like this
import com.atlassian.jira.component.ComponentAccessor
import static com.atlassian.jira.issue.IssueFieldConstants.*
def formField = getFieldById(PRIORITY)
def optionsMap = ComponentAccessor.getConstantsManager().getPriorities().findAll { priority ->
priority.getName() in ["High", "Medium"]
}.collectEntries {
[(it.id): it.name]
}
formField.setFieldOptions(optionsMap)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Awesome, that worked like a charm !!
@Alexey Matveev you are indeed a Champion. :) Thank you so much for taking time to help me with this, totally appreciate it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Awesome, that worked like a charm !!
@Alexey Matveev you are indeed a Champion. :) Thank you so much for taking time to help me with this, totally appreciate it.
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.