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

Serj Shcherbakov June 17, 2016

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
Serj Shcherbakov June 20, 2016

@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
0 votes
Mahesh S
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events