JIRA validation Required

Kalpana Ramesh August 22, 2016

I need to add validation if custom field is not equal to some of its options. If so, then another field becomes a mandatory field.

We tried the following SIL code but it is not working

string errorMsg = "Field was not initialized!";
string test = customfield_11700;
if ((test != "No") || (test != "Neither"))
{
    if(!hasInput("Mandatory Field")) 
    {
   return false, "Mandatory Field", errorMsg; 
}
}

1 answer

0 votes
Błażej O_
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.
August 22, 2016

I'm not sure if I understand correctly but you have made a mistake in the logic condition. You're getting success if test is either different then "No" or "Neither". So when test equals "No" it IS different then "Neither", or the other way around, you're getting a success smile In fact you're always getting a success with this condition (the only possibility for the failure would be if test would be equal to "No" and "Neither" IN THE SAME TIME, and that is not possible).

Try this:

string errorMsg = "Field was not initialized!";
string test = customfield_11700;
boolean success = true;
if ((test == "No") || (test == "Neither"))
{
	if(!hasInput(customfield_XXXXX)) //XXXXX is the id of your "Mandatory field"
	{
		success = false;
	}
}

return success, customfield_XXXXX, errorMsg;

 

EDIT: corrected mistake in code.

Kalpana Ramesh August 22, 2016

Hi Blazej! Thanks for your response.
While trying your SIL, i am able to validate my customfield. If test = "No" or test = "Neither" gets validated, then a field has to become mandatory. But that is not happening. How can we do that?

 

Błażej O_
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.
August 23, 2016

I looked into the documentation and it says that hasInput() must be called with customfield_XXXXX as a parameter. I've tried the script locally, yet it still fails, with some odd results.

I'll try to look at it a bit deeper, and if I will not find an error I'll raise a support ticket at producer's tracker.

If you want you may try alternate method to work this out:

string errorMsg = "Field was not initialized!";
string test = customfield_11700;
boolean success = true;
if ((test == "No") || (test == "Neither"))
{
    if(isNull(#{Mandatory Field})) 
    {
        success = false;
    }
	else
	{
		success = true;
	}
}
 
return success, #{Mandatory Field}, errorMsg;

Suggest an answer

Log in or Sign up to answer