Jump to content

Order for criterions in custom expressions


Alisha
 Share

Recommended Posts

Hello,

Sometimes when creating captures I accidentally add custom expressions in the wrong order and have to delete them to put them in the right order. Would it be possible to add arrow buttons so that we can easily change the order please? Similar to how we can change the order of form fields (see second image attached).

Many thanks,
Alisha

Hornbill.jpg

Hornbill2.jpg

Link to comment
Share on other sites

  • Victor changed the title to Order for criterions in custom expressions
  • 3 months later...
  • 1 month later...

@Alisha - one thing you (and anyone building complex expressions) needs to be aware of is boolean operator precedence. In Hornbill (and I think in most IT systems) the AND operator has precedence over the OR operator. I will try and explain what this means with an example where you have 3 criterions in an expression:

  • a = 1
  • a = 2
  • b = 3

Let's say your expression looks like this: a = 1 OR a = 2 AND b = 3

Without knowing the operator precedence rule, one might look at this and think that this will match if: a has either of the values of 1 and 2 and in addition of all this, b has a value of 3. However, this is not how the expression is actually evaluated because of the operator precedence, this will be matched: first, a has a value of 2 and also, at the same time b has a value of 3. If not, then secondly the whole expression will also match if a has the value of 1.

This can be also explained a bit better by using brackets which help override the default operator precedence. So back to our example:

a = 1 OR a = 2 AND b = 3

With no brackets this will execute like this:

a = 1 OR (a = 2 AND b = 3)

Assuming you want the OR evaluated first then using brackets you can "force" different precedence:

(a = 1 OR a = 2) AND b = 3

 

 

 

Expanding on the above, using some information from the screenshot and showing the implications of changing criterion position within expressions. Let's say the expression is:

Global Variable -> Service == Service 1

OR

Global Variable -> Service == Service 2

AND

Global Variable -> Source == Email

One might think this expression will produce a positive match in one scenario that Service is either 1 or 2 and in addition to service values, the source is email. Based on the above explanation this will not work like this, instead, this will produce a positive match in the following two scenarios, either of them will produce a positive match:

  • Global Variable -> Service == Service 1
  • Global Variable -> Service == Service 2 AND Global Variable -> Source == Email

To achieve the result you would need from the above, which is to produce a positive match only if the source is email and Service is 1 or 2, you would need to build your expression like this:

Global Variable -> Service == Service 1

AND

Global Variable -> Source == Email

OR

Global Variable -> Service == Service 2

AND

Global Variable -> Source == Email

 

 

 

Going back to the initial expression, let's say you move the "Email" criterion on top:

Global Variable -> Source == Email

AND

Global Variable -> Service == Service 1

OR

Global Variable -> Service == Service 2

Again, one might think this expression will produce a positive match in one scenario that the source is email and in addition, service is either 1 or 2. Again, based on the above explanation this will not work like this, instead, this will produce a positive match in the following two scenarios, either of them will produce a positive match:

  • Global Variable -> Source == Email AND Global Variable -> Service == Service 1
  • Global Variable -> Service == Service 2

 

You can see now that by moving the "email" criterion on top produced this result:

  • Global Variable -> Source == Email AND Global Variable -> Service == Service 1
  • Global Variable -> Service == Service 2

as opposed to what result produced when the email criterion was last:

  • Global Variable -> Service == Service 1
  • Global Variable -> Service == Service 2 AND Global Variable -> Source == Email

Therefore one needs to be quite mindful of repositioning the criterions to ensure the expressions produce the result the one needs. I know all this might sound complicated but happy to detail any parts that need clarifying.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...