Behavior to add a description when multiple values are selected

Mihai Mihai September 24, 2019

Hello,

We have a multi select list field with different values. It is called 'Tool/s' . (values are: JIRA, Confluence, Github , etc).

We want that a description is added to the 'description' field when certain values are selected in the 'Tool/s' field:

def Tools = getFieldByName("Tool/s")
def descField = getFieldById("description")

def toolsvalue = Tools.getValue()
if (toolsvalue.toString().contains("JIRA")) { // choose tools by name
descField.setHelpText("text added here.")
descField.setRequired(true)
} else if (toolsvalue.toString().contains("Github")) {
descField.setHelpText("a different help text ")
descField.setRequired(true)
}
else if (toolsvalue.toString().contains("Confluence")) {
descField.setHelpText("confluence specific text")
descField.setRequired(true)
}
else {
descField.clearHelpText()
descField.setRequired(false)
}

This works when individual values are selected. But "Tool/s" is a multiple select list, and the above code does not work when both "JIRA" & "Confluence" are selected, or when all of the values are selected.

Please let me know if that would be possible, and how.

 

Thank you!

 

1 answer

1 accepted

2 votes
Answer accepted
fran garcia gomera
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.
September 25, 2019

It's not working because else if only applies if previous if/else if were false

Something like this, obviously taking care of adding the correct format between texts

def finaltext = ""

if (toolsvalue.toString().contains("JIRA")) { // choose tools by name
finaltext = "text added here."
}

if (toolsvalue.toString().contains("Github")) {
finaltext = finaltext + "a different help text "
}
if (toolsvalue.toString().contains("Confluence")) {
finaltext = finaltext + "confluence specific text"
}
if (finaltext=="" {
descField.clearHelpText()
descField.setRequired(false)

}else{

descField.setHelpText(finaltext)
descField.setRequired(true)
}
Mihai Mihai September 25, 2019

Thank you, that's great!

Suggest an answer

Log in or Sign up to answer