JIRA validation Required

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

This widget could not be displayed.

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.

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?

 

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
Community showcase
Asked yesterday in Data Center

Hi! I'm Cameron Deatsch, enterprise enthusiast and Head of Server at Atlassian. AMA!

Hey team! I'm Cameron Deatsch, Head of Server at Atlassian. At our European Summit just a few weeks ago, I spoke about the latest regarding our Server and Data center products and o...

19,316 views 4 4
View question

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