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
Published Monday in Jira Ops

Jira Ops Early Access Program Update #1: Announcing our next feature and a new integration

Thanks for signing up for Jira Ops! I’m Matt Ryall, leader for the Jira Ops product team at Atlassian. Since this is a brand new product, we’ll be delivering improvements quickly and sharing updates...

507 views 0 9
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