Hi All,
We are having multiple request types in our Service desk (Jira request,Infra request & Devops request)based on which custom field(select list) options should be listed down & hide unwanted category values.
So kindly help us to achieve this uscing Scriptrunner behaviours.
Thanks in Advance
BR,
Revathy Madhavan
Hi @chithra madhav Kindly apply Behaviour on Issue Type :-
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.*
def issuetype = getIssueContext().getIssueType().name
def selectcf = getFieldByName("Sub-type") // replace with your custom field name
selectcf.setFormValue(null)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def customField = customFieldManager.getCustomFieldObject(selectcf.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
//replace issue type names in Conditions
if (issuetype.contains("Custom Product")) {
def optionsMap = options.findAll {
it.value in ["Custom Requests","Survey Project Management","Proposals"]
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
selectcf.setFieldOptions(optionsMap)
}
else if (issuetype.contains("Data Innovations")) {
def optionsMap = options.findAll {
it.value in ["Comp. Tool Technical Help"]
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
selectcf.setFieldOptions(optionsMap)
}
else {
def optionsMap = options.findAll {
it.value in ["Job Matching Assistance Only", "Standard Data Extract","Job Matching and Data Extract","Prevailing Wage"]
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
selectcf.setFieldOptions(optionsMap)
}
Hi @Vikrant Yadav ,
I tried to update the script in Behaviours but getting the below error ,please help to fix this!
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @chithra madhav You can ignore this error message. Try to save the script and check if it's working or not.
Let me know, if it's not working for you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Kindly share the script, if it's not working for you. I'll try to fix it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Vikrant Yadav ,
PFB,script used in Behaviours and also attached the field used instead of Issuetype
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @chithra madhav Thanks for sharing the script.
You applied script at wrong place. Add Script for Issue Type field.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.*
def issuetype = getIssueContext().getIssueType().name
def selectcf = getFieldByName("Network _Category_Service request") // replace with your custom field name
selectcf.setFormValue(null)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def customField = customFieldManager.getCustomFieldObject(selectcf.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
//replace issue type names in Conditions
if (issuetype.contains("Bug")) {
def optionsMap = options.findAll {
it.value in ["US"]
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
selectcf.setFieldOptions(optionsMap)
}
else if (issuetype.contains("Story")) {
def optionsMap = options.findAll {
it.value in ["International"]
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
selectcf.setFieldOptions(optionsMap)
}
else {
def optionsMap = options.findAll {
it.value in ["Job Matching Assistance Only", "Standard Data Extract","Job Matching and Data Extract","Prevailing Wage"]
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
selectcf.setFieldOptions(optionsMap)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Vikrant Yadav ,
I have a checkbox field & select list field in Jira Service desk.
I want to hide the checkbox field options based on particular value selected from the Select List(basically based on the select list options, checkbox options need to be enabled in the Create & Edit Screen).
I tried multiple scrips in Behaviours server side & Initializer sections but no luck!
Please help me on this request.
Select List Field -- Application Type(Value1--AAA,Value2--BBB)
Checkbox Field -- Sub-System(Values--ABC,DEF,XYZ)
Expected Result:
if Application Type value 1 is selected then the checkbox should display one 2 options(ABC & XYZ) .
Else if Application Type value 2 is selected then the checkbox should display one 1 options(DEF) .
Regards,
Revathy.M
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @chithra madhav If it's select list field then why not added issuetype.contains in your script. Anyways below script is based on select list field.
Kindly mark the solution as accpeted if it works for you.
Apply behaviour on Select List field :-
import com.atlassian.jira.component.ComponentAccessor
def application = getFieldById(getFieldChanged())//select list field
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def test_checkbox = getFieldByName("Test Checkbox")//checkbox field
def customField = customFieldManager.getCustomFieldObject(test_checkbox.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
def optionsToSelect = options.findAll { it.value in ["US","IN","NZ"] } //checkbox field options which you want to show based on one value of select list field
def optionsToSelect1 = options.findAll { it.value in ["UK","UAE","SA"] } //checkbox field options which you want to show based on another value of select list field
//condition based on select list field value
if (application.getValue() == "1"){
test_checkbox.setFieldOptions(optionsToSelect)
} else if (application.getValue() == "2"){
test_checkbox.setFieldOptions(optionsToSelect1)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Vikrant Yadav ,
Thank you for the update.
I tried the above script in the server side as well as Initializer but still it is not working as expected.
Shared the screenshot & script for referrence.
Kindly help me to fix the issue.
Script Used:
Thanks !
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Behaviour mapping is correct ?
Only one Sub-system field is available in Jira right ?
Are these custom fields or plug-in fields?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Vikrant Yadav ,
As per your update we have changed the checkbox field name, since the previous name already exists with the different field.
Thanks you so much it works as expected.
Regards,
Revathy.M
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@chithra madhav Instead of changing the name, you can use Field Id.
Anyways It's great news. Glad to hear i am able to help you out :)
Kindly mark the solution as Accepted. As it help other people looking for same solution.
Thanks
V.Y
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you @Vikrant Yadav , great solution, it also works for me
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Vikrant Yadav
I am getting the same error as that of chitra. I ignored the error and saved the code and tried, but unfortunately it failed, i.e. the request type is not showing option based on the issue type. I used the same code which you provided above. Could you help with this?
Thank you.
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.