Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Behaviour Script for Multiselect field in Jira Cloud

Imran Khan September 13, 2023

I written this script for the multiselect field for the option visibility, when I select Option 1 in multiselect field  it is going to if condition and if I select both the options in multiselect field it is not passing to else statement still stays in the "1st If condition of OPTION1" 

I'm looking in a way when I select multiple option in multiselect field it should directly move to else statement by skipping the if conditions and if I select the single option it should look to IF condition

Below is the code I written 

const changeField = getChangeField()
const field = getFieldById("customfield_10079")  --->multiselect field id

if(changeField.getName() == "Select List (Multi)")

{
let podName = field.getValue()
let value = podName.map(c => c.value)

if(value.toString().includes("Option 1")){
getFieldById("customfield_10047").setOptionsVisibility(["10130","10026"],true)
}
else if(value.toString().includes("Option 2")){
getFieldById("customfield_10047").setOptionsVisibility(["10027"],true)
}
else{
getFieldById("customfield_10047").setOptionsVisibility(["10026", "10027", "10130", "10154"],true)
}

1 answer

1 vote
Florian PEREZ [Valiantys Administrator]
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.
November 15, 2023

Hello @Imran Khan

Hope you're doing well ! 

I Would do something like this with feld I created for the matter of the example( tested on my instance and working fine): 

const colorField = getFieldById("customfield_10088") // Single select
const colorsField = getFieldById("customfield_10093") // Multi select
const changedField = getChangeField()

const colorsValue = colorsField.getValue().map(c => c.value)
const colorsValueString = colorsValue.toString();

if (changedField.getName() == colorsField.getName()) {
const hasRed = colorsValueString.includes("Red");
const hasBlue = colorsValueString.includes("Blue");
const hasGreen = colorsValueString.includes("Green");

if (hasRed || hasBlue || hasGreen) {
colorField.setRequired(true);

let options = [];
if (hasRed) options.push("10156");
if (hasBlue) options.push("10157");
if (hasGreen) options.push("10158");

colorField.setOptionsVisibility(options, true);
}
}

Hope this help.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events