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; } }
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 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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.