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.
Hi,
I would like to create a behavior that will show some options for the sub-issue type based on the issue type. I have 3 issue types and 9 options, this is what I have found so far but it doesn't make any change at all :(
customfield_15303is the selectable list with the values for the sub-types.
Can someone help pls?
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
int selectListId = 15303
def selectList = getFieldById("customfield_15303" + selectListId)
String issuetype = getIssueContext().getIssueType().getName()
def map
switch (issuetype){
case "Production":
map = ["Defect", "RFS", "RFI"]
break;
case "Change Request":
map = ["CR", "Additional Requirement", "Sub-task"]
break;
case "Defect":
map = ["Pre-UAT defect","UAT defect", "SIT defect"]
break;
}
if (map != null){
def optionsManager = ComponentAccessor.getOptionsManager()
def selectListCustomField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(selectListId)
def fieldConfig = selectListCustomField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(fieldConfig)
def optionsMap = options.findAll {
it.value in map // list of options you want to show
}.collectEntries {
[
(it.optionId.toString()) : it.value
]
}
selectList.setFieldOptions(optionsMap)
}
Hey PaulaA,
You did not properly grab your field:
int selectListId = 15303
def selectList = getFieldById("customfield_15303" + selectListId)
Where it should be:
int selectListId = 15303
def selectList = getFieldById("customfield_" + selectListId)
Now everything should work :)
Also, if you have ScriptRunner 6.26.0 and above, there is a better way to do this. We have introduced a better way to work with behaviour: Behaviour Enhancement
Now you can pass a list of String instead of the option IDs!
Ultimately, your script could be simplified to this:
int selectListId = 15303
def selectList = getFieldById("customfield_" + selectListId)
String issuetype = getIssueContext().getIssueType().getName()
def map
switch (issuetype) {
case "Production":
map = ["Defect", "RFS", "RFI"]
break;
case "Change Request":
map = ["CR", "Additional Requirement", "Sub-task"]
break;
case "Defect":
map = ["Pre-UAT defect","UAT defect", "SIT defect"]
break;
}
if (map) {
selectList.setFieldOptions(map)
}
I hope this helps!
Cheers,
Helmy
Hi @Helmy Ibrahim _Adaptavist_ ,
thanks a lot! it works and you version is definitely easier.
Just another question, the user wants to have sub-task on the secondary subtype, but I cannot select it but sub-task is actually like a separate issue type instead, do you know if there's an option to select it properly?
I'm not even sure if it makes any sense to have sub-task, I'd use task but just in case it's possible so we can have all options.
Thanks again!! :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi PaulA,
I am sorry for not following. But could you please add some screenshots and a use case for a better understanding?
Cheers,
Helmy
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.