Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

hide options from select list field values based on Request type selected

chithra madhav July 14, 2022

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

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
2 votes
Answer accepted
Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 14, 2022

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)


}  
chithra madhav October 26, 2022

Hi @Vikrant Yadav ,

I tried to update the script in Behaviours but getting the below error ,please help to fix this!

Thanks!

Customer Request Type & Category field.PNG

Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 26, 2022

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.

Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 26, 2022

Kindly share the script, if it's not working for you. I'll try to fix it. 

chithra madhav October 27, 2022

Hi @Vikrant Yadav ,

PFB,script used in Behaviours and also attached the field used instead of IssuetypeCustomer Request Type.Network Category.PNG

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.*


def issuetype = getIssueContext().getIssueType().name


int numberId = 15608
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("Network Request")) {
def optionsMap = options.findAll {
it.value in ["Load Balancer","SVN","Firewall","Backup/Restore","VPN"]
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
selectcf.setFieldOptions(optionsMap)
}
else if (issuetype.contains("Jira Request")) {
def optionsMap = options.findAll {
it.value in ["Jira","Confluence"]
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
selectcf.setFieldOptions(optionsMap)
}
else {
def optionsMap = options.findAll {
it.value in ["Load Balancer","SVN","Firewall","Backup/Restore","VPN","Jira","Confluence"]
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
selectcf.setFieldOptions(optionsMap)
}  



Thanks!
Like Vikrant Yadav likes this
Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 28, 2022

Hi @chithra madhav  Thanks for sharing the script.

You applied script at wrong place. Add Script for Issue Type field. 

 

Issue Type Behaviour.PNG

 

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)

}  
chithra madhav November 10, 2022

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

Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 10, 2022

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)

}
Like # people like this
chithra madhav November 10, 2022

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:

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("Sub-System ")//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 ["SVP","PCS","EDI"] } //checkbox field options which you want to show based on one value of select list field

def optionsToSelect1 = options.findAll { it.value in ["C4BB","PDEX","ADMINPORTAL"] } //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() == "EvoBrix X"){

    test_checkbox.setFieldOptions(optionsToSelect)

   

} else if (application.getValue() == "FHIR"){

    test_checkbox.setFieldOptions(optionsToSelect1)

}



Checkbox field hiding based on Select List.PNG

Checkbox field hiding script in behaviours.PNG


Thanks !

Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 10, 2022

Behaviour mapping is correct ?

Only one Sub-system field is available in Jira right ? 

Are these custom fields or plug-in fields?

chithra madhav November 10, 2022

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

Like Vikrant Yadav likes this
Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 10, 2022

@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

Parvaneh Zand
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 8, 2023

Thank you @Vikrant Yadav , great solution, it also works for me

Like Vikrant Yadav likes this
Harsh
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 18, 2024

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.

TAGS
AUG Leaders

Atlassian Community Events