Recalculate or validate calculated control on form submit?

  • 13 July 2016
  • 4 replies
  • 27 views

Badge +4

Hi, I have run into a scenario with a form that I am struggling with.  I created a signup form for a client that allows people to sign up for a volunteer shift.  There are a certain number of openings for any given shift.  I have a related list that contains all of the available shifts and the number of openings.  When a request is submitted, a workflow subtracts one available shift from the related list of openings.  On the request form, you choose a shift, and a calculated control does a lookup to the related list and displays the number of openings. 

The calculated control formula is as follows:

lookup("Shift Openings", "ID", Shift , "Openings")

If the number of shifts is less than 1, a formatting rule displays the number of openings bold and in red, and then a validation rule will prevent the person from submitting it.

nintexformvalidation1.jpg

This was working perfectly well and I didn't see the gap in the logic until we ran into a scenario today...

Two people were filling out a request for the exact same shift at the same time.  The calculated control on the form looked at the related list and displayed 1 opening.  Person A, then submitted their form and the workflow subtracted 1 opening.  Person B had selected the shift prior to Person A's workflow subtracting 1 opening, so Person B's form was also showing 1 opening in the calculated control.  Both were submitted and the result was the shift was overbooked and now has -1 available. 

I know I can add a condition in the workflow to check, but I'd prefer to give instant feedback to the submitter and allow them to select another shift with out having to submit a new form.  So, this brings me to my question... Is there a way I can force that calculated control to recalculate when the Save/Submit button is clicked, or can I have that button click do some kind of lookup validation and prevent it from being submitted if the number of shifts becomes 0 before the person submits it?  Other approaches are welcome too.  I'd prefer to do it without JavaScript if possible, since I am not very strong in that area.

Thank you very much!

Brian


4 replies

Badge +6

Hi Brian,

Could you put a Validation Rule on the Save button using the lookup function to check whether the slot has been booked as the submit button is pressed?

Cheers,

Mark

Badge +4

Mark,

I love where you're going with this.  For some reason, it hadn't occurred to me to do it that way.  I added this condition as a validation rule on the Submit button:

lessThan(lookup("Shift Openings", "ID", Shift, "Openings"), 1)

It isn't doing exactly what I need it to do though.  It seems like it isn't doing the lookup at the time I click the button, but rather when the shift is selected.  Those that appear with less than 1 opening are invalid, those that have 1 or more are submitting correctly, but when I start filling out the form (with one opening in the related list), and then remove the available openings, it still lets them through and the result is the negative number of openings again.

I am not sure if I am setting it up incorrectly, or if this is just normal behavior and it should calculate the value when the shift is selected instead of when the button is pressed.

Any additional thoughts on this are appreciated.

Thanks,

Brian

Badge +6

Hi Brian,

I have done some testing too and have replicated your results. It appears that the lookup on the submit button validation rule occurs at the time of the form loading and not on form submission - which is a bummer. sad.png You may need to resort to Javascript to do your dirtywork here. I am not a Javascript guru, so hopefully someone else here can help.

Cheers,

Mark

Badge +4

Hi Mark,

Thanks for testing this and validating the findings.  I wasn't sure if I just had it set up wrong or something. 

If anyone else had some ideas for this, I'd love to hear them.

Thanks!

Brian

Reply