I’m having problems with the following Input Validation code. It works in test with a button click but not with Input Validation so I think it may relate to @SetField not triggering?
I’m using hidden txtAgentFlag on the form.
Any assistance most welcome.
@SetField(“txtAgentFlag”;“0”);
@If(@IsMember(kwdReason;txtReasonsSalesMan);@SetField(“txtAgentFlag”;“1”);“”);
@If(@IsMember(kwdReason;txtReasonsCSDMan);@SetField(“txtAgentFlag”;“1”);“”);
@If(txtAgentFlag=“1”;
@If(txtAgentCode<>"";@Success;
@Failure("Please enter an Agent Code and click Get Agent Name."));
@SetField(“txtAgentCode”;“”))
Subject: RE: Input Validation Problem - @SetField
I know of no reason you can’t use @SetField in an input validation.
However: an input validation formula’s result must be either @Success, or a string containing an error message. There’s only one exit point from your formula (since you don’t use @Return) so the return value of the formula is the return value of the last value-returning statement, the @If which begins on line 6. There are three possible paths through the @If – one returns @Success. One returns a string using @Failure. The third path calls @SetField. What does the third path return, success or failure?
If the above does not solve your problem, we need more information about what you’re doing. If you’re not sure what information to supply, the C R I S P Y document might help you. In particular, the phrase “does not work” is very uninformative; as if there’s only one way for something to fail. What does it do instead of working?
- Andre Guirard, IBM/Lotus Development
Useful blog: Best Practice Makes Perfect
Subject: RE: Input Validation Problem - @SetField
Andre, thanks for the prompt response.
Apologies for not supplying enough information. It was the end of a long frustrating day! However you did answer my query in so much as confirming @SetField should work for Input Validation.
In isolation, the @Success/@Failure code works but the problem is perhaps with the @IsMember validation. When executing, if the kwdReason matches txtReasonsSalesMan or txtReasonsCSDMan then the validation works (but the txtAgentFlag value does not appear to get set on the form). If the kwdReason is another value then the messagebox “Field Containts Incorrect Value” “field didn’t pass validation formula” is triggered.
Essentially what I want to do is make sure that if the customer has selected one of two specific Reasons then they must also enter an Agent Code. This is a fix to an existing application I’ve inherited.
I’ll step through your recommendation but if you have any further advise it would be most welcome.
Subject: RE: Input Validation Problem - @SetField
I think I’ve cracked this.
@SetField does work but as suspected it doesn’t display on the form.
Andre rightly pointed out that the third exit path failed to contain a success or failure.
The following code appears to work:
@SetField(“txtAgentFlag”;“0”);
@If(@IsMember(kwdReason;txtReasonsSalesMan);@SetField(“txtAgentFlag”;“1”);“”);
@If(@IsMember(kwdReason;txtReasonsCSDMan);@SetField(“txtAgentFlag”;“1”);“”);
@If(txtAgentFlag=“0”;@SetField(“txtAgentCode”;“”);“”);
@If(txtAgentFlag=“1”;
@If(txtAgentCode<>"";@Success;@Failure("Please enter an Agent Code and click Get Agent Name."));
@Success)
Thanks again, Andre.