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,298,084
Community Members
 
Community Events
165
Community Groups

Make the fields mandatory based on another select (multi select) field

Hi Team,

 I would like to make these fields mandatory ( European Retailer, History/Format Change, Legacy Migration, TV2 Migration, TPD Document Type) when Product Type is "Data Engine" , here Product Type is select List (multiple Choices), I am using below script, but not able to make the fields mandatory. Could anyone please check and correct the script where i did miss it ?

 

def europeanField = getFieldByName("European Retailer")
def historyField = getFieldByName("History/Format Change")
def legacyField = getFieldByName("Legacy Migration")
def tv2Field = getFieldByName("TV2 Migration")
def tpddocField = getFieldByName("TPD Document Type")
def producttypeField = getFieldByName("Product Type")

def producttypeValue = producttypeField.getValue()

if (producttypeValue == "Data Engine")

{
europeanField.setRequired(true)
historyField.setRequired(true)
legacyField.setRequired(true)
tv2Field.setRequired(true)
tpddocField.setRequired(true)

}

else {
europeanField.setRequired(false)
historyField.setRequired(false)
legacyField.setRequired(false)
tv2Field.setRequired(false)
tpddocField.setRequired(false)

}

 

Thanks!

1 comment

Hi @Lakshmi S  For Multi Select List field method is little bit different from Single Select list :- 

https://library.adaptavist.com/entity/get-the-values-of-a-multi-select-field

Kindly modify below code as per your requirement. 

import com.onresolve.jira.groovy.user.FieldBehaviours
import org.apache.log4j.Logger
import org.apache.log4j.Level
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours
def log = Logger.getLogger(getClass())

// Set log level
log.setLevel(Level.DEBUG)

def multiSelectField = getFieldByName('producttypeField')
// Value for a multi-select field will always be a list even if "None" is selected
def multiSelectFieldValue = multiSelectField.value as List

def description
// If value is null
if (multiSelectFieldValue == [null]) {
description = 'Multi Select Field is set to None'

// If a given string is selected
} else if (multiSelectFieldValue == ["Data Engine"]) {
europeanField.setRequired(true)
historyField.setRequired(true)
legacyField.setRequired(true)
tv2Field.setRequired(true)
tpddocField.setRequired(true)

// If more than 1 value is selected
} else if ( multiSelectFieldValue.size() > 1 ) {
description = 'Multi Select Field has more than 1 value selected'
}

log.debug(description)
multiSelectField.description = description
Like Lakshmi S likes this

Thank you @Vikrant Yadav  for your quick response.

I have corrected my code as per your doc and its working fine.

 

import com.onresolve.jira.groovy.user.FieldBehaviours
import org.apache.log4j.Logger
import org.apache.log4j.Level
import groovy.transform.BaseScript

def europeanField = getFieldByName("European Retailer")
def historyField = getFieldByName("History/Format Change")
def legacyField = getFieldByName("Legacy Migration")
def tv2Field = getFieldByName("TV2 Migration")
def tpddocField = getFieldByName("TPD Document Type")
def producttypeField = getFieldByName("Product Type")


def producttypeValue = producttypeField.value as List

@BaseScript FieldBehaviours fieldBehaviours
def log = Logger.getLogger(getClass())

 

if (producttypeValue == ["Data Engine"])

{
europeanField.setRequired(true)
historyField.setRequired(true)
legacyField.setRequired(true)
tv2Field.setRequired(true)
tpddocField.setRequired(true)

}

else
{
europeanField.setRequired(false)
historyField.setRequired(false)
legacyField.setRequired(false)
tv2Field.setRequired(false)
tpddocField.setRequired(false)

}

Like Vikrant Yadav likes this

Cool! Glad to hear it works for you :)

Comment

Log in or Sign up to comment
TAGS

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