Error Trapping before querysave event

I have code in my querysave event that sends an email using @MailSend based on a field’s status. This works fine but in cases where an error occurs in another field on the form during an attempted save (field validation formula) the email is being sent in spite of the field error then again when the error is corrected an the form is saved. How can I prevent the querysave event from sending the email if all field validations have not been successfully met?

Thanks in advance

Subject: Error Trapping before querysave event

Are there reasons you couldn’t put the code in the postsave event?

Do you want to send an e-mail each time someone saves?

If not, then it may make the most sense to move it to the queryclose.

Subject: Error Trapping before querysave event

Any reason not to do it in the PostSave?

Subject: RE: Error Trapping before querysave event

Thanks for the quick response.

My original reason for doing it in the querysave event was because part of the code that triggers the email is based on whether the document is newly created (@If(@IsNewDoc; @MailSend…). If I put this same code in the postsave it wouldnt send the email for newly created docs unless I create a workaround. Now that you’ve made a great suggestion, I guess I could simply create a hidden field that populates based on whether the doc is new or not and then test against that field in the postsave event.

Subject: Error Trapping before querysave event

2 suggestions:

  1. I’m assuming you have some type of “Save and Close” button? Probably coded like this:

@Command([FileSave]);

@Command([FileCloseWindow]);

Change that to :

@If(@Command([FileSave]); @Command([FileCloseWindow]); “”);

That won’t really solve your problem but tends to play nicer with code in your queryclose (if you move it there).

  1. Add code to your querysave to force validation and only continue if validation passes. i.e. add this as the first line of your querysave:

@If(@IsValid; “”; @Return(“”));

That of course will re-run your validation but will stop execution of the rest of your code.