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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,555,881
Community Members
 
Community Events
184
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

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.
Aug 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

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.
Aug 31, 2021

Cool! Glad to hear it works for you :)

Comment

Log in or Sign up to comment