Behavior pluging - Making field mandatory in create screen based on multiple conditions

Vidhya Mohan February 20, 2020

I'm trying to make the field production impact mandatory based on the values selected in 4 other fields. I want this on the create bug scree? can someone please tell me if this server side script is correct?

 

def selectCFValue1 = getFieldByName("Detected in (Test) Stage").getValue()
def selectCFValue2 = getFieldByName("Business Risk").getValue()
def selectCFValue3 = getFieldByName("Prod Defect Category").getValue()
def selectCFValue4 = getFieldByName("Defect Impact Type").getValue()
def targetField = getFieldByName("Production Impact")

if (selectCFValue1.getValue() == "5-Warranty" || selectCFValue1.getValue() == "7-Prod") &&       (selectCFValue2.getValue() == "1-Blocking") &&
(selectCFValue3.getValue() == "Ordering" || selectCFValue3.getValue() == "Selling") &&(selectCFValue4.getValue() == "Exceptions" || selectCFValue4.getValue() == "IT Tickets" || selectCFValue4.getValue() == "EXOs"|| selectCFValue4.getValue() == "Non-Processed"|| selectCFValue4.getValue() == "YY exceptions" || selectCFValue4.getValue() == "Pending ")
targetField.setRequired(true)
else
targetField.setRequired(false)

1 answer

1 accepted

0 votes
Answer accepted
Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 24, 2020

Hi @Vidhya Mohan ,

You are using getValue() twice on the fields and missed some parenthesis. Please try : 

def selectCFValue1 = getFieldByName("Detected in (Test) Stage").getValue()
def selectCFValue2 = getFieldByName("Business Risk").getValue()
def selectCFValue3 = getFieldByName("Prod Defect Category").getValue()
def selectCFValue4 = getFieldByName("Defect Impact Type").getValue()
def targetField = getFieldByName("Production Impact")

if ((selectCFValue1 == "5-Warranty" || selectCFValue1 == "7-Prod")
&& (selectCFValue2 == "1-Blocking")
&& (selectCFValue3 == "Ordering" || selectCFValue3 == "Selling")
&& (selectCFValue4 == "Exceptions" || selectCFValue4 == "IT Tickets" || selectCFValue4 == "EXOs"|| selectCFValue4 == "Non-Processed"|| selectCFValue4 == "YY exceptions" || selectCFValue4 == "Pending ")) {
targetField.setRequired(true)
}
else {
targetField.setRequired(false)
}

Antoine

Vidhya Mohan February 25, 2020

thank you. this worked

Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 25, 2020

You are welcome ! If you are satisfied with the answer pleae mark it as accepted so it can help others too.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events