Send email based on field value but then reset the field with a Record Rule Afterwards

So here is my problem:

I want to send an email based on whether a fields is marked YES, but after the form has been submitted I want the field to be marked NO.

This is to stop a user inadvertently logging back in and then forgetting to set the YES to NO.

The way I had this setup, which doesn’t work, is to have an Email Rule so that when the form was submitted it would then check for the field value and dispatch an email.

To reset I had Record Rule that basically sets the field to NO upon submit.

Guess what…turns out the email rule fires after the Form Submit Rule so nothing gets dispatched.

I could do a task that runs at midnight that sets all the values of the Email rule to No, but just wondered if there was another way. For example, when the form loads automatically set a field to a certain value (IE NO!).

Thanks for any help.

I have suffered the same frustration on more than one occasion. I use Make to reset the field back on from submission. This is a bit of extra work but it ensures the field is reset almost instantly rather than on a scheduled task. There may be a way of doing this with JavaScript but as I’m not a coder the Make solution serves the purpose.

Another option if you don’t use Make may be to do it like this:

  1. User submits form and email is sent.
  2. User is directed to a child page where a form (with no inputs) auto-submits and a record rule sets the field to ‘No’. As it auto-submits they barely even see the page apart from a split second as it loads.
  3. User then redirected to a page of your choice.

To get a form to auto submit you need this very short bit of JS. Just replace the XXX with your scene number:

/* Auto-submit form */
$(document).on('knack-scene-render.scene_XXX', function(event, scene) {
    // Knack Standard Theme:
1 Like

@Hugo - that’s a good workaround :+1:
Definitely one of those “why didn’t I think of that” situations :rofl:
I use the auto form submit on many other use cases, just never thought to use it for this one. Nice solution, I’ll use this next time I have to set a value back.

@Hugo, that’s a neat method! I love it!

Here is a non-code method to throw in the mix:

  1. Add two identical yes/yo or multiple choice fields in your table, one named
    ‘Send email’ and the other named ‘Send email [email trigger]’.

  2. On your form, display the first ‘Send email’ field.

  3. Add two record rules: One that copies the value from the ‘Send email’ field to the ‘Send email [email trigger]’ field, and a separate one that resets the value of the ‘Send email’ field.
    I believe Knack runs these rules asynchronously.

  4. Finally, set up your email rule to trigger from the ‘Send email [email trigger]’ field value:

Thanks all for your feedback on this. It’s great to see the different ways this can be accomplished. I think what I may end up doing is a midnight task on the system that resets the field values while all the users are asleep. Be good if there was an inherent hierarchy in the existing workflow that would force some kind of firing order to exist between a Record Rule and a Submit rule, so this was hardwired. In this case it’s simply that omission that makes setting this up impossible without some kind of KnackDevMagic :slight_smile:

That’s clever @StephenChapman , trying to think in what situations that could be used as an alternative to an extra page with an auto-submitting form…

1 Like