cancel
Showing results for 
Search instead for 
Did you mean: 
Workflow Hero

Validation on field with multiple rules

Jump to solution

I am having trouble with a Validation on fields. I currently have fields that require multiple situations to apply. I cannot get the formula to work when I have more than one per field. I tried doing them as separate rules too. I might of missed something so I am asking for help. 

Field Name is Agree w/Impact Statement

Logic:

If Review Status is No Applicability then Agree w/Impact Statement is required

If Review Status is Currently Compliant then Agree w/ Impact Statement is required

If Action Plan Complete Date is not Blank and Review Status is Implemented then Agree w/Impact Statement is required

If Review Status is Informational and Communication sent is not blank then Agree w/Impact Statement is required

Validation:

((Review Status,"No Applicability")  && isNullOrEmpty({Self})) || ((Review Status,"Currently Compliant")  && isNullOrEmpty({Self})) || ((Review Status,"Implemented")  && (Action Plan Complete Date,not(isNullOrEmpty())) || ((Review Status,"Informational")  && (Communication Sent,not(isNullOrEmpty()))

Please let me know what I should be doing to get this to work cause I have like 6 more fields to apply similar logic to. 

Labels: (1)
0 Kudos
Reply
10 Replies
Workflow Hero

Re: Validation on field with multiple rules

Jump to solution

When working with logic like this, it's usually best to try and group all of your identical fields so that as you're thinking about it in your head, it becomes less confusing. 

Because I have no idea what type of fields {Review Status} or {Communication Sent}, I'm going to assume that {Review Status} is a Choice field, and {Communication Sent} is a Single Line Text (because you use the phrase 'Not Blank'. Depending on your actual Controls, how you write the final rule may vary slightly.

Let's rewrite your logic using some common grouping:

If Review Status is No Applicability then Impact Statement is required

If Review Status is Currently Compliant then Impact Statement is required

If Review Status is Implemented and Action Plan Complete Date is not Blank then Impact Statement is required

If Review Status is Informational and Communication Sent is not blank then Impact Statement is required

That's a lot easier to read because you have the same variable ({Review Status}) in the same position for each condition. We can also see that the variable ({Impact Statement}) is always in the same place. 

Now lets group 'like' conditions. We see that there are two (2) lines of conditions at the top that are VERY similar. We know that if the {Review Status} equals "No Applicability" OR "Currently Compliant" that we want to require the {Impact Statement}. We also know that because there is an 'and' statement in the last two conditions, we'll have to let them live on their own not-grouped. This should clue you in as to the direction the final rule should take. 

Using how we have now organized the layout of the logic, we can start to think about the shape of the rule. We know that the end will always be the same for all of these but will only ever need to be checked if the starting conditions are actually true. So let's start our rule looking like: 

() && isNullOrEmpty({Impact Statement})

Now we need to consider each one of our conditions that would make us want to check the {Impact Statement}. Because we have already accounted for the {Impact Statement} when we look at our conditions left to fulfill, we can leave off anything having to do with it. Adding some additional markup to our 'written' conditions would leave us with something looking like: 

If (Review Status === No Applicability) ||

If (Review Status === Currently Compliant) ||

If (Review Status === Implemented && Action Plan Complete Date === not Blank) ||

If (Review Status === Informational && Communication Sent === not Blank)

As mentioned above, the first two conditions are really similar. We can rewrite our written conditions to: 

If (Review Status === No Applicability ||

    Review Status === Currently Compliant) ||

If (Review Status === Implemented && Action Plan Complete Date === not Blank) ||

If (Review Status === Informational && Communication Sent === not Blank)

Without adding any of the actual references or values to our Rule, the above syntax would look like when paired with the first draft of our Rule: 

(( || ) || ( && ) || ( && )) && isNullOrEmpty({Impact Statement})

Now that we have the layout of the logic / conditional operators, it's just a matter of adding in the actual substance of your written conditions into this Rule: 

(({Review Status} === "No Applicability" || {Review Status} === "Currently Compliant") || 
({Review Status} === "Implemented" && !isNullOrEmpty({Action Plan Complete Date})) ||
({Review Status} === "Informational" && !isNullOrEmpty({Communication Sent}))) && isNullOrEmpty({Impact Statement})

Again, this might be a little different based on the type of Controls that you're actually using, but shouldn't be too different from how the overall structure of this is. Also, you'll need to replace the placeholders {Review Status}, {Action Plan Complete Date}, {Communication Sent}, and {Impact Statement} with their respective actual Nintex Form References as simply copying and pasting the above code will not work. 

I hope that this helps you to achieve what are you are trying to set out to do. 


Reply
Workflow Hero

Re: Validation on field with multiple rules

Jump to solution

First off, thanks for chiming in and trying to help. However when I used the following code replacing the controls and item properties appropriately (I think) it still did not function. I did not receive a prompt on the field when trying to submit.

((Review Status === "No Applicability" || Review Status === "Currently Compliant") || 
 (Review Status=== "Implemented" && !isNullOrEmpty(Action Plan Complete Date)) || 
 (Review Status === "Informational" && !isNullOrEmpty(Communication Sent))) && isNullOrEmpty(Agree w/Impact Statement)
I am also not sure if you meant to or not but I did notice the "!" be for the isNullorEmpty. I am not sure what that does or if its a typo. 
I apologize for my lack of understanding here. I also am on the NintexForms 2016 On Premise if that makes a difference. 
 Review Status is a Item Property also available as a named control
Communication Sent is a Date field
All other fields are just item properties. 
0 Kudos
Reply
Workflow Hero

Re: Validation on field with multiple rules

Jump to solution

When you place an exclamation point in front of a boolean value in JavaScript, it reverses it. 

isNullOrEmpty() returns true if the control that it is evaluating is empty

However, when we're checking if something isn't empty, then we need 'reverse' the returned value. Consider the following.

isNullOrEmpty("Hello World"); // returns false;

!isNullOrEmpty("Hello World"); // returns true;‍

--------------------

From the looks of your post, you say that {Communication Sent} is a Date Control? Perhaps then the best thing to do would be to NOT include your dates inside of the Rule to validate your {Impact Statement} control. 

Why? 

Because they should have their OWN validation rules to make users input them! This would then make the Validation Rule on  your {Impact Statement} control look something like: 

(({Review Status} === "No Applicability" || 
  {Review Status} === "Currently Compliant" ||
  {Review Status} === "Implemented" ||
  {Review Status} === "Informational") && isNullOrEmpty({Impact Statement}))

This way, if your Review Status is any of those (4) values, and the Impact Statement is blank, it will tell the user to FIX IT.

Put rules on your Date controls as needed to make sure that they get validated on their own as well. 

No matter what, you end up with a form that cannot be submitted without first inputting all of the required information. 


0 Kudos
Reply
Workflow Hero

Re: Validation on field with multiple rules

Jump to solution

So enter that code did not work either on making the field required. So I kind of simplified it down just to get it working. 

(Review Status,"No Applicability") || (Review Status, "Currently Compliant") && isNullOrEmpty({Self})

After doing this it worked to require it no matter what what selected. And if I changed any value or set them all back to null it still would not update the form and allow it to be submitted. 

I have no other rules running other than this one were trying to get working. Also I am testing using the preview, which I am assuming should be fully functional. 

0 Kudos
Reply
Workflow Hero

Re: Validation on field with multiple rules

Jump to solution

I'm not entirely sure why you're code looks the way it does. 

(Review Status, "Some Word Here") doesn't actually do anything on its own. Is there some type of Runtime Function call that you're making that you are not including in your examples here? 

If you're testing for equality, that is: does 1 equal 1? Then you would need to write something like 

1 === 1, and not (1,1). 

It might be helpful if you could post a screenshot of your form, your controls, etc. etc. as it becoming increasingly difficult to troubleshoot by word alone. 

I also encourage you to, because you're using SharePoint 2016 and persumably the Nintex Forms 2016, to run the form using the Chrome Browser (from google) and take a screenshot of any errors it shows in the developers console while the form is being launched. You can get to the developers console using F12. 

0 Kudos
Reply
Workflow Hero

Re: Validation on field with multiple rules

Jump to solution

I have provided the screen shots below. Also I am using Chrome (only way to go). 

0 Kudos
Reply
Workflow Hero

Re: Validation on field with multiple rules

Jump to solution

Any other thoughts on how to get this working? 

0 Kudos
Reply
Workflow Hero

Re: Validation on field with multiple rules

Jump to solution

What I would recommend is to create Three (3) Validation Rules. 

Rule 1, on control {Agree w/Impact Statement}: 

(Review Status === "No Applicability" || Review Status === "Currently Compliant" || Review Status === "Implemented" || Review Status === "Informational") && isNullOrEmpty({Control:Self})

Rule 2, on {Action Plan Complete Date}: 

Review Status === "Implemented" && isNullOrEmpty({Control:Self})

Rule 3, on {Communication Sent}: 

Review Status === "Informational" && isNullOrEmpty({Control:Self})

This way you create a nice catch for all of your cases and simplify the rules across the board

This should work unless you have some off cases that just can't fit into this scheme. 

If it really is the case that you can do something like select "Informational" for the Review Status, but then NOT set a Communication Sent date, then I would suggest just breaking those out into their own rules instead of trying to consolidate them down as they do not lend themselves to being squashed together alongside other similar logic. 

hope this helps. 


Reply
Workflow Hero

Re: Validation on field with multiple rules

Jump to solution

Thank you so much for being patient and getting me there. I realized what I was doing in addition to some syntax. I was using the Item Properties field instead of the Control within the formula. Makes all the difference. 

Thank You.

0 Kudos
Reply