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 Join to answer
Community showcase
Teodora [Botron]
Published Feb 15, 2018 in Marketplace Apps

Jira Inferno: The Nine Circles of Jira Administration Hell

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...

1,223 views 6 19
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot