Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Show/Hide select list multichoice field values based on a drop down value

Hi Team,

I have a script which I wrote that hides/shows fields based on a selection in a drop down using script runner behaviours.

There is a select list (single choice) named 'Single/Multiple users' with values "single" and "multiple users". Based on the selecting of the 'Single/Multiple users' certain fields are hidden which works fine. 

import com.atlassian.jira.issue.IssueFieldConstants
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

final String fieldName = "Disclaimer"

// get field by name and make it read only// get field by id and make it read only
//getFieldById(IssueFieldConstants.DUE_DATE).setReadOnly(true)

def CField1= getFieldByName("Bulk upload - Users")
def CField2= getFieldById("attachment")
def CField3= getFieldByName("First Name")
def CField4= getFieldByName("Last Name")
def CField5= getFieldByName("Employee Alias")
def CField7= getFieldByName("Standard Bank Email Address")
def CField8= getFieldByName("Disclaimer")
def CField9= getFieldByName("Please note :")

def TCType = getFieldById(getFieldChanged())
def selectedOption = TCType .getValue() as String

if(selectedOption=="Single User")
{
CField1.setHidden(true)
CField7.setHidden(true)
CField2.setHidden(true)
CField3.setHidden(false)
CField4.setHidden(false)
CField5.setHidden(false)
CField7.setHidden(false)
CField8.setHidden(true)

}

else if (selectedOption=="Multiple Users")
{
CField1.setHidden(false)
CField2.setHidden(false)
CField3.setHidden(true)
CField4.setHidden(true)
CField5.setHidden(true)
CField7.setHidden(false)
CField8.setHidden(false)
getFieldByName(fieldName).setReadOnly(true)

}

I need to amend the script for a scenario to hide values in a select list multichoice field :

case :

1. If I select single user - select list(multi choice) field show's all values e.g Jira, confluence, Bamboo, Bitbucket.

2. if I select multiple users - select list(multi choice) field  hides some values e.g Jira, confluence

Do I need to add conditions within the scripted field to cater for the use case ? 

 

1 answer

Hi @Nic Brough _Adaptavist_ 

Thanks for the script.

I have added the initialiser but nothing is triggered.

Please advise.

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

final singleSelectListName = 'Single User'
final multiSelectListName = 'Multiple User'
final referringtool = 'Referring Tool'

[singleSelectListName,referringtool, multiSelectListName].each { selectFieldName ->
// Get the select field
def selectField = getFieldByName(selectFieldName)

// Getting select field options
def selectCustomField = customFieldManager.customFieldObjects.findByName(selectFieldName)
def selectConfig = selectCustomField.getRelevantConfig(issueContext)
def selectOptions = ComponentAccessor.optionsManager.getOptions(selectConfig)

// Filter select available options
final selectAvailableOptions = selectOptions.findAll { it.value in ['Bamboo', 'Bitbucket', 'Confluence Enterprise', 'Jira Enterprise'] }
selectField.setFieldOptions(selectAvailableOptions)

// Set the default values depending on select type
if (selectFieldName == singleSelectListName) {
def defaultValue = selectAvailableOptions.find { it.value == 'Bamboo' }
selectField.setFormValue(defaultValue.optionId)
} else if (selectFieldName == multiSelectListName) {
def defaultValues = selectAvailableOptions.findAll { it.value in ['Bitbucket', 'Confluence Enterprise'] }
selectField.setFormValue(defaultValues*.optionId)
}
}

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
Community showcase
Published in Jira

Do you use Jira Cloud with Microsoft Teams?

Hi, Jira users! Do you use Jira alongside Microsoft Teams? We want to hear how you’ve used the power of Jira Cloud and Microsoft Teams (via the Jira Cloud for Microsoft Teams app) to achieve a team...

461 views 3 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you