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 vote
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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Marketplace Apps

Tips on how to choose the best estimation method for your planning

Planning and grooming sessions all come with their own sets of rules. Team members meet to estimate stories or other work items, all according to an agreed-upon process. And with every session comes ...

67 views 0 11
Read article

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