Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

Lakshmi S August 30, 2021

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

Comment

Log in or Sign up to comment
Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 30, 2021

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
Lakshmi S August 31, 2021

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
Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 31, 2021

Cool! Glad to hear it works for you :)

TAGS
AUG Leaders

Atlassian Community Events