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

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 Join to answer
Community showcase
Teodora [Botron]
Published Thursday 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 ...

413 views 1 13
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