Input Validation and an '|'

Can someone help me understand why the following @If fails when used in the Input Validation.

If “720” is entered in the Code field, it fails; however, if “761” is entered, the validation works.

@If(@IsDocBeingSaved & Code != “720” |

@IsDocBeingSaved & Code != “761”;

@Failure(“Location incorrect, please reselect Loctn/Dept”);@Success)

It has to do with the “|” but what…

Subject: Input Validation and an ‘|’

Try

@If (

@IsDocBeingSaved & Contains(Code;“720”:“761”);

  @Failure("Location incorrect, please 

    reselect Loctn/Dept");

  @Success

)

That being said. Is there a reason why you are doing this as an input validation formula as opposed to validation in the QuerySave event?

Subject: Thanks for your response File Save.

No reason not to use the QuerySave; however, the ‘|’ symbol should work in the @If statement, shouldn’t it???

I actually am trying to check the field for the single value of “720” OR if the field is => “751” and <= “769”.

That is why I’m try to get the ‘|’ work.

Subject: RE: Thanks for your response File Save.

First off, if the values are text, then this isn’t very good validation. “759025766543” is greater than “751” and less than “769” when compared as text.

Try this:

selectedCode = @ToNumber(Code);

@If(@IsDocBeingSaved & (selectedCode = 720 | (selectedCode >= 751 & selectedCode <= 769)); @Success; @Failure(blurb))

Subject: Thanks for your help Stan, I really appreciate it!!

Your code example appears to be working fine in my simple test. The values I’m checking for, the field code, only contains 3 digit numbers.

Thanks again!

Subject: RE: Thanks for your response File Save.

When I saw the @TexttoNumber, the ‘light’ came on…

Subject: RE: Thanks for your response File Save.

Validation really should be done in the QuerySave if there is not a business need to have it in the field. This (1) keeps the code in one place and makes it easier to manage; and (2) reduces the number of refreshes a user has to deal with as each field gets validated.

tmpCode:=Code;

@if ((@TextToNumber(tmpCode) = 720) | ( 751 <= @TextToNumber(tmpCode) <= 769)

Subject: RE: Thanks for your response File Save.

I’m afraid I have to strongly disagree – I would prefer that all validation be done in the provided validation events because it’s obvious (indicated by the little icon in the object browser), navigation to the affected field is immediate and automatic and it can optionally be made to fire in-process rather than waiting for a save. Each to his own, but since field validation and nav-back is unique per field, having all the code in one place is no particular advantage.

Subject: RE: Thanks for your response File Save.

From a code maintainability purpose, I would argue it is better. When you have to make a change to an application, what is easier, slogging through each field or going to a common code base to make sure chnages do not impact existing validation.

Also, this allows you to move the definition of validation rules out of the code and into the hands of the business process owner.

Subject: RE: Thanks for your response File Save.

Ain’t nuttin’ you can do in the QuerySave you can’t do in a Validation event (including getting profiled rules), and I still argue that it’s easier to “find” the validation code for a particular field when it is AT the field rather than on line 7223 of a library used in a library used in an event. I’ve never understood the centrality argument for object-specific code – the proper place for object-specific code is in the class/object.

I don’t want this to degrade to a religious war or anything – I can’t see any better, more logical, or more discoverable place for field validation than at the field itself. You have another opinion (that’s wrong ;o) ), and our poor victim has a choice.

Subject: RE: Thanks for your response File Save.

But how can I be wrong when you are the one that is wrong!?:slight_smile:

Subject: RE: Thanks for your response File Save.

If I may add my 2 cents here, i’d add a few comments.

  • If you put code in the query save event, you can argue that there might be SEVERAL query save events… for the main form, but for the subforms also if any… unfortunately for teh headache of the poor LN developer!

  • On the other hand, sometimes, you need to trigger a refresh: from a dialog box choice, from a button, from an event, etc. At this point all the validation formulas are triggered, which can be erally annoying since the user didn’t try to save or to check his values, and we only wanted that one specific value to be refreshed. In this situation, I prefer adding my validation formulas in the querysave - or in the workflow action, if it applyes to this form.

So really… it depends… :wink:

Nicolas Abesdris

Quintessence e-solutions Inc.

Subject: RE: Thanks for your response File Save.

Okay, now – taking the middle road is wronger than being firmly in one camp or the other. File and I can only be wrong half of the time at most; you’ve allowed the possibility to be wrong all of the time, and when the religious war really starts, both sides will call you a heretic :slight_smile:

Subject: RE: Thanks for your response File Save.

Whaaaaa :)I can take it :slight_smile: I’ve been called a heretic quite a few times in my carreer! grin

Subject: RE: Thanks for your response File Save.

I address this issue in “Better Compliance through Lotus Notes/Domino Coding” published in the Jan 2005 issue of “Lotus Advisor” ( http://lotus.advisor.com/doc/14900 ).

Subject: Thanks File Save!!

Subject: Input Validation and an ‘|’

Are you certain yo know what order the booleans are being evaluated in? Try putting parentheses around the parts, or better yet, rewrite it like this:

@If(@IsDocBeingSaved & !(Code=“720”:“761”);@Failure(blurb);@Success)

Subject: Stan, I sure think so!

Your code will work for sure, but still need to get the ‘|’ symbol to work. I set a simple test and can not get the ‘|’ not matter how I rewrite the code.

Are you able to use the ‘|’ in a simplet test? If so, can you explain what I’m missing.

Thanks!

Subject: RE: Stan, I sure think so!

Stan’s question can be rephrased as “Do you know boolean operator precedence (or at least how Notes implements it, which isn’t quite correct), and therefore does your code do what you think it does?”

Subject: RE: Stan, I sure think so!

See the response above. It should do the trick.