You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hello all,
Within Behaviors, I'm trying to figure out how to pull the "Value" of the issue type field drop down within the create screen in order to set specific options within a single select customfield (Client).
So far I have this:
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def IssueTypeField = #????#
def IssueTypeFieldValue = #????#
log.warn("issue type value = ${IssueTypeField}")
def ClientField = getFieldByName("Client")
def optionManager = ComponentAccessor.optionsManager
def customFieldManager = ComponentAccessor.customFieldManager
def ClientFieldCustomField = customFieldManager.getCustomFieldObject(ClientField.fieldId)
def ClientFieldConfig = ClientFieldCustomField.getRelevantConfig(issueContext)
def ClientFieldOptions = optionManager.getOptions(ClientFieldConfig)
def allAppOptions = [
"Issue-Type-#1": ["Client A"],
"Issue-Type-#2": ["Client A", "Client B"],
]
if (allAppOptions[IssueTypeFieldValue]) {
ClientField.setFieldOptions(allAppOptions[IssueTypeFieldValue])
} else {
ClientField.setFieldOptions([])
}
Can someone help?
Thanks,
Mike
When you're on 'Create' normal field getters won't work, because the issue doesn't exist. There is a different way to get it by reading it off the current context:
def issueTypeName = getIssueContext().getIssueType().getName()
Which does change also if you switch issue types midway through the form.
Other than that, I'm not sure whether the way you're trying to set field options will work, this seems a bit sus with nested string lists:
def allAppOptions = [
"Issue-Type-#1": ["Client A"],
"Issue-Type-#2": ["Client A", "Client B"],
]
If it doesn't, see https://docs.adaptavist.com/sr4js/latest/features/behaviours/api-quick-reference on how to get it to work.
Hi Radek,
The above code for the issue type name:
def issueTypeName = getIssueContext().getIssueType().getName()
Worked like a charm, and so did the original "def allAppOptions" coding.
Thank you very much!
~Mike
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.