Groovy Validator: if numeric field is not equals "0" or NULL, the another multiselect field is required.

Hi, i'll tried this but my result is still failed sad

if (cfValues["Product gap (w/o contingency, md)"] != null) || if (cfValues["Product gap (w/o contingency, md)"] != "0")  {
    if (! cfValues["TOMS Modules"]) {
        return false
    }
}
true

2 answers

0 votes
Mahesh S Community Champion Jun 17, 2016

Try this script.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueImpl
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
  
IssueManager issueManager = ComponentAccessor.getIssueManager()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField myCustomfield1 = customFieldManager.getCustomFieldObjectByName("Product gap (w/o contingency, md)")
String myCustomfield1Val = (String) issue.getCustomFieldValue(myCustomfield1)
CustomField myCustomfield2 = customFieldManager.getCustomFieldObjectByName("TOMS Modules")
String myCustomfield2Val = (String) issue.getCustomFieldValue(myCustomfield2)
if((myCustomfield1Val != null) || (myCustomfield1Val != "") || (myCustomfield1Val != "0"))
{
	if((myCustomfield2Val == null) || (myCustomfield1Val == ""))
	{
		return false
	}
}
return true

@Mahesh S hi, thanks for solution.
But this issue still unresolved.

Please look at my scenarios:

  1. My numeric field is empty, but select list is still required
    How it should in this case: rule: if number is empty that select field should be not required


    image2016-6-20 13:41:48.png
     
  2. My numeric field equal "0", but select list is still required
    How it should in this case: if numeric field equal "0" that select field should be not required



    image2016-6-20 13:42:26.pngHope you help,
    many thanks Sergey

Suggest an answer

Log in or Sign up to answer
Community showcase
Asked Dec 06, 2018 in Jira Ops

I'm John Allspaw, Ask Me Anything about incident analysis and postmortems

I'm John Allspaw, co-founder of   Adaptive Capacity Labs, where we help teams use their incidents to learn and improve. We bring research-driven methods and approaches to drive effective inciden...

5,664 views 22 17
View question

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you