Just When You Thought Validatrix Could Not Get More Complicated…

One of the problems of offering a tool that can create custom business rules for almost any scenario is that it has to have a lot of functionality. As we developed Validatrix we realised that some of that functionality was missing so we added it on. The problem with that of course is that the more you add on the more complicated the application becomes.

We have attempted to remedy this by offering the Validatrix Query Converter which does a good job of converting queries into rules and is often a good starting point for expanding a rule further.

We realised that we had missed out on a piece of functionality that was preventing us from creating a rule with a specific scenario. It is possible to all sorts of logic within one rule. We can check if a field value is exactly the same as another, if it is not the same as if it is greater than or less than etc.

Dependencies

When we talk about how dependencies interact there are only three possibilities corresponding to the three dependency boxes.

The first is an AND box. This means that all rules in the box must be met. The second is an OR box. This means that one or another or both must be met. Finally we have what is referred to in logic as a NOR box. This is the opposite of OR. If one rule is met or another one or both then the rule will not be met. This box ensures that none of the rules in the box are met .

There is one more scenerio that we did not account for. We want to rule to fire when not dependency 1 AND dependency 2 are met. i.e. when neither of them are met. This is the NAND box and is opposite to the AND box.

The Implementation

Before I move on to an example, it is worthwhile pointing out how this has been implemented. Beneath the first box (the AND box) there is now a checkbox which prompts us to “Do the reverse logic”. When checked, the text above the box now reads “Any number EXCEPT ALL of these rules must be met” as shown below.

NAND logic

 

 

 

 

 

An example

So how would you use this in a real example?

If a gift is over £1000 the constituent should have a “Major Donor” constituent code and also have a “Do Not Solicit” solicit code.

This is a tricky one as there appears to be a number of ways of doing this but in fact the most obvious ways are all wrong!

The primary rule is straight forward as we just check to see if the gift we are saving is greater than £1000. There are two dependencies

  1. Whether they have the constituent code and
  2. whether they have the solicit code.

Below is a table outlining the different permutations and, assuming that the gift is over £1000,  what result we want to achieve.

ScenarioHas the solicit code?Has the con code?Show the message?
1NoNoYes
2NoYesYes
3YesNoYes
4YesYesNo
  • If we put both dependencies in the “All of these rules must be met” box then the message will be shown only for scenario 4
  • If we put both dependencies in the “At least one of these rules must be met” box then the message will be shown for scenarios 2,3 and 4.
  • If we put both dependencies in the “None of these rules must be met” box then the message will be shown for scenario 1 only

By using our “Reverse the logic” checkbox the message will be shown as intended.

 

Further Reading

If you are struggling with the logic then check out this link which has a few nice explanations (don’t follow the links that talk about electronics)

If you would like to see this rule broken down into its components then head on over to our Validatrix Recipe area of our main website.