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

Behavior to add a description when multiple values are selected

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

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

Thank you, that's great!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

The add-in you’ve been waiting for: Jira Cloud for Excel 🙌

Introducing Jira Cloud for Excel Here at the product integrations team at Atlassian, we are thrilled to announce the new Jira Cloud for Excel add-in! This add-in lets you export Jira data directly ...

947 views 8 25
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