Workflow to validate if Date & Time falls within a range and avoid double booking?

  • 21 November 2018
  • 18 replies
  • 38 views

Badge +11

Hello all,

I require help with setting up a workflow process which checks if the selected date & time does not fall within the range of existing date within a custom list in sharepoint 2016 onpremise.

Similarly, I asked somebody to code a JS code to validate on the form:
https://community.nintex.com/message/85369-re-how-to-check-if-a-date-time-falls-within-a-range-and-avoid-double-booking?… 

can such validation also be performed when the form is submitted via workflow?? Thus is to ensure that the date does not exist in the custom list which may happen if 2 users submit a request within a time at similar time.

Cheers,


18 replies

Badge +8

Hi Bimi,

How do you intend to submit the form "via" the workflow? Any JS you add on the form will only be executed at the client side but workflows wont trigger the JS unless there is a user interaction.

Regards,

Shrini

Badge +11

Hi,

In this case it will be only workflow process.
The JS already validates the date/time at the submission process ... but imagine if two users submit same entry at same time, the script would not be able to validate happy.png and thefore the workflow would act as a backup.

I found this topic   but I fail to understand it.

Badge +8

Hi Bimi,

The post above "Prevent Double booking" probably does the same check on the WF to prevent double booking. I havent gone into the details of it, but assuming your case would be similar but not exactly same?

In your case I assume if the form is doing the check then you may have to repeat the steps again in the workflow to be sure, but when we do any check in the workflow its a delayed action, i.e the user may not know if his request his successful or not until the workflow does the check and somehow notifies the user (through emails?) whether the booking is successful or not which is not a very ideal User experience.

In your current setup I am assuming you must be checking for the double booking in JS and that should occur at the very end just before the record gets saved into the DB, so if 2 users open at the very same time but 1st user saves it earlier, then when the 2nd user is trying to save it the JS will anyways do a fresh check on the validation and error out? Is this not the case? 

Regards,

Shrini

Badge +11

Hello Shrinivas Naik

In regards to the JS validation How to check if a Date & Time falls within a range and avoid double booking? it does validate at the on-change as well as when Submit button is clicked happy.png in theory your assumption should work; if user1 submits the request 5 seconds before the user2 .. but this may not be the case due to delays in process etc etc.

Therefore, the Workflow then checks (after the submission has gone) to ensure the dates do not fall in range.

I have implemented the WF suggestion by Darren1372 ( ) and kind of addapted to my needs but I am new to the loops etc and fail to understand the process.

Did you check my email sent to you?

Badge +8

Hi Bimi,

I haven't seen your code so cant really comment, but in theory when any user tries to save the entire saving process including checking for the duplicate through javscript should hardly take 1 or max 2 secs, so the probability of another user saving at the exact 1-2 sec window would be highly unlikely. Even then doing a double check by using your workflow should be okay as well. Its just more defensive. But in your workflow what do you do when there is a duplicate? Do you email the user back and tell them its not successful?

Where are you stuck in your workflow, from a very high level view of the workflow link it appears as though he is checking the main list (meeting rooms) and may be adding  a filter for the same room in question and just loops through records where start time is in between the start and end date. This would at least give him all the records that are clashing. The logic seems okay at a high level, where are you stuck though?

Regards,

Shrini

Badge +11

the JS code is here https://community.nintex.com/message/85369-re-how-to-check-if-a-date-time-falls-within-a-range-and-avoid-double-booking?… 

Badge +11

But in your workflow what do you do when there is a duplicate?
Do you email the user back and tell them its not successful?

Yes, the workflow needs to email the user asking to select different dates in the form.
Now, the keypoint is that the Validation Procoess needs to re-run with the new selected dates.

To achieve this, the STATE MACHINES needs to be implemented.
The issue with this is that it taked up to 5 - 10min for the worflow to go through the sate machines
It is a default timing and you cannot make it quicker ...

Now, within the 5-10 span another user could potetially claim the new selected date because he started it earlier.

Anyway happy.png need to think this through, if the WF validation is really needed??

Besides that, each request needs to be approved by the manager.
Which also means, each request with the dates gets recorded to the list but as such being reserved.

Badge +11

WHAT IS THE PROBLEM

The problem is that when I submit a request with fresh date/time which does not exisit in the table then the workflow goes through the look and identifies that the "just submitted date/time" exist and then clashes with the date!

The process is as following:

1) user opens the form

2) user selects the date

3) JS validation promps if the dates already exist

4) user submits selected dates and the workflow starts

5) worklow goes throug the loop and gatheres all the ID's and compares the dates

6) workflow identifies that the user's selected dates exist in the list (this is because he just submitted them).

In other words, the loop goes through after the form is submitted and thefore will always find the double booking
cos the data is saved into the custom list and the workflow runs which lookups in the list for dates...

it is a catch 22 situation!

How do I overcome this ... sad.png

Badge +8

Hi Bimi,

Apologies trying to balance quite a few things here so not going into very detail. I might question that we could design this in a different way.

To achieve this, the STATE MACHINES needs to be implemented.
The issue with this is that it taked up to 5 - 10min for the worflow to go through the sate machines
It is a default timing and you cannot make it quicker ... 

You mentioned you are using State Machines? Why do you use that ? State machines will run when the time job runs and that will run how it is scheduled in your SP farm. It could be 5 mins or more. Why would you want to use state machine ? You might want to start processing when the item changes and not use state machine?

regards,

Shrini

Badge +8

Just to add you are also have an approving mechanism here?

May be we design the entire thing in a different way?

1) User books the meeting room through the form

2) Form does the validation to see if the room is booked, if booked (errors out) if not booked then BOOKS it

3) Workflow will then be triggered which can send approval to manager. If approved then all is well if rejected then UNBOOK it. (similar to cancelling a meeting room!)

Scenario

1) Let User 1 add the Room 1 between 9-10 am

2) Form for User 1 does the validation (which your existing code would be handy) and books it 

3) User 1 approval goes to your manager and depending if he approves or rejects ( if you using Task based approval i.e. assign flexi task or Assign task then it will depend on the timer job to create and manage stuff for you!) In this time if User 2 tries to book in that instant then the form will throw a validation error as the room is already booked (even if its tentative)

4) if User1s manager rejects his booking then the workflow will release the booking and it will again be available for anyone else to book.

Am i missing something here?>

Regards,

Shrini

Badge +8

HI Bimi,

Please refer to my earlier approach I replied to one of your questions I think the design can be a bit different ..

I just saw this reply  .. if you issue is just so that WF is trying to select the same row which the form has entered, you can add an extra check to see if the booking was made by the same person and then "not" consider this as an existing booking?

Regards,

Shrini

Badge +11

This is what it came to my mind on the way home thinking "... why does it happen" and yes, checking that the entry is NOT EQUAL current person will only check other's entries and this should work in theory happy.png

I shall test this out.

Badge +11

My workflow is about booking a car... which is similar to booking a conference room.
Yes, that is my inttention: simply to ensure that no double booking occures.

The JS validation does the front-ent validation and the workflow does the back-end validation.
Now, either I change the query to rule out ID which are raised by CurrentUser or not to include wf validation at all?

Badge +8

Sure let me know what comes out of it ..

Regards,

Shrini

Badge +11

Just to visualise the process, see below:

Attention:

+ the JS validation is a front-end validation which is triggered when filling in the form.
+ the WORKFLOW VALIDATION step is a questionmark whether it is really required etc.

Let's take two scenarios into consideration:

1) Perfect Scenario (ignore the Workflow Validation step in this case):

- User1 requests a car on 25/11/2018 10:00 - 26/11/2018 13:00

- The request gets validated via JS and finds no overlap

- The request is now is now pending for approval
- User2 requests a car on 25/11/2018 15:00 until 25/11/2018 16:30  (which is overlapping the above)

- The JS validation of course picks it up and shows the alert message

- The user is forced to select a different date / time range!

2) Worst Scenario (ignore the Workflow Validation step in this case):

- User1 and User2 submit a request at similar timing which is a low chance but not un-avoidable!
- User1 selects 25/11/2018 10:00 - 26/11/2018 13:00
- User2 selects 25/11/2018 15:00 until 25/11/2018 16:30 

- Both requests go through without any issues because the JS validation (due timing) does not find duplicate

- Both requests will go for approval request and when they get approved = there is an overlap / doublebooking

Now this is where I thought, to implement a WORKFLOW VALIDATION step as seen in the picture (red dot). This step would then go through the list and compare the selected times, and this is where the User2 requests would be thrown back due to double booking as from what I could analyse.

When the workflow identifies a doublebooking > it informs the user to edit the form and resubmit with new date/time. For such action, a STATE MACHINE is required which can send a process back to a previous step, thus is to re-validate the request.

Or maybe... the state machine is not required because when user re-submits the request, the JS validation checks the existing entries?!

HINT:

The LOOP action contains a query and in there I will have to add (if current user is not equal created by) so that it ignores the user's fresh request otherwise it will always pick up a double booking!!

UPDATE

I have now completed the workflow as following:

1) The form validates the selected dates via the JS Validation Script
2) The workflow goes through a validation check to ensure there is no double entry in the list via Query (Current User != Created by)

3) The requests will be pending for approval requests (may add a wait until XY days and then automatically decline if it exceeds the selected date)

4) Notify the user when it has been approved or rejected and the workflow is then complete.

5) Review the request if the workflow validates a double booking and delete the request if user does not respond after 5 days.

I did not introduce StateMachines but rather in-one-line workflow.

Badge +8

Hi Bimi,

Thats a good depiction of the current process flow happy.png ..

Just to be curious your only issue was that the workflow selecting its own records and you could circumvent that by quering all the records minus the current user records ? I am assuming that is sorted ?

With regards to your process flow and the workflow ..  if you have already created it then its probably better to use it.

When the workflow identifies a doublebooking > it informs the user to edit the form and resubmit with new date/time. For such action, a STATE MACHINE is required which can send a process back to a previous step, thus is to re-validate the request.

This is not required. I suggest when you see there is a double booking by the workflow you should email the user and then "END" the workflow. After the user 2 resubmits his request (the form validation would always kick in to check for any double booking) and he can resubmit for approval. A new instance of the workflow would then be triggered and can function as it should.

if that helps?

Regards,

Shrini

Badge +11

Yes, that would be the case: to exclude the current user at the query step.

As per the State Machine, I think I will not implement it but use as a run-down flow.
When the WF finds a duplicate > it sends email to user asking to edit the form and resubmit with new date/time.
If there is no respond within 5 days then the workflow will delete the request and end the process.

Badge

The date and the time are always changing - imagine the tedious task of validating if the Date & Time fall within a range. Here you can get best uk writing services some new tips of education. As a business, you don't want to lose money through double booking if one of your customer's books on both your website and another competitor's website at the same time. Workflow allows you to set up different fixed times for particular booking processes.

Reply