I have a “Validate” button that should check for empty fields in a document. It does that okay, but also pops up the error twice. I’ve included the button code below; what can I do to solve this? I’d really appreciate any help with this.
@Command([EditDocument];“1”);
@If(@IsValid;
@If(@PostedCommand([FileSave]);
@Do(@SetField(“Status”;“2”);
@SetField("StatusText"; "Validated");
@SetField("Tracking";@Explode(@Implode(Tracking;"~") + "~" + "Document Validated on " + @Text(@Now) + " by " + @Name([CN];@UserName);"~"));
@PostedCommand([FileSave])); "");
@Return(""))
Subject: Input Validation
I suspect that your @isvalid is firing your validation event once and making the message pop up, and then the form save command is causing the validation event to fire again.
Subject: RE: Input Validation
I’m not sure I understand the purpose of the message recorded in Tracking field. Since there is no way to save the document without the validation formulas executing, what’s the purpose of recording a note that the validation formulas were executed? Someone edited the document, so obviously it was validated.
You have to take this one part at a time and see where it’s failing. The fact that you see a message twice, leads me to think that @IsValid must be returning True. That would result in two saves. Put in @Prompt statements or @Statusbar so that you can see the values of functions as you go along.
What are the input validation formulas? Are they written in such a way that they might return @Success if you aren’t yet saving the document? E.g. @If(@IsDocBeingRecalculated; @Success; @ThisField = “”; “Field may not be blank”; @Success)? That might account for @IsValid returning True even though there are errors when you try to save.
Do not change these validation formulas; that’s the way I recommend writing them. Instead, don’t use @IsValid.
If you read the help for @PostedCommand, you will see that all it does during the execution of the formula is remember that you want to execute the command after the formula finishes executing. The return value of @PostedCommand can’t tell you whether the command succeeded, because it hasn’t been attempted yet. Use @Command instead, then the return value means something.
In this case, I don’t see why you don’t assign the Tracking field first (if you must) and try to save. If the save fails, delete the last entry in Tracking. That way, you only save one time, which is more efficient.