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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,466,226
Community Members
 
Community Events
176
Community Groups

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

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

1 vote
Answer accepted
Vikrant Yadav Community Leader Jul 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)


}  

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 Oct 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 Oct 26, 2022

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

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 Oct 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)

}  

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 Nov 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 chithra madhav likes this

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 !

Behaviour mapping is correct ?

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

Are these custom fields or plug-in fields?

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 Nov 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

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events