CAML request with Sharepoint to avoid calendar overlap reservations

I use the Calendar List for some room orders, everything is in order, but only struggles with Overlapp or double booking the room on the same day and time.

I am trying to figure out by passing the data entered by the user in the form to CAML Query and check if this record exists or not.

If the entry already exists, cancel the reservation or if it will not continue.

For example: if From: 10:00 AM to 11:00 AM already ordered.

overlap scenarios can be:

if the user enters the form From: 10:00 AM to 10:30 AM

From: 9:00 AM to 11:00. I guess the date is the same, and only time matters to me.

How to get a CAML request if the date is the same and only the time changes and checks the user input “From” and “B” when there are already reserved elements in the range.

using the request below but not checking for all scenarios

<Where><And><Geq><FieldRef Name='EventDate' /><Value IncludeTimeValue='TRUE'  Type='DateTime'>" + strSPEventDateFormat + "</Value></Geq><And><Leq><FieldRef Name='EndDate' /><Value IncludeTimeValue='TRUE' Type='DateTime'>" + strSPEndDateFormat + "</Value></Leq><Eq><FieldRef Name='Room' /><Value Type='Lookup'>" + strCheckRoomAvail + "</Value></Eq></And></And></Where>

Please help me with this.

Thanks in advance

+3
source share
1 answer

Write CAML so that all rooms conflict with the start time. The start time should not be between the start and end time selected by the user. ALSO write CAML so that all rooms contradict END Time. END time must not be between start and end time selected by user

If the number chosen by the user is not in the above results returned by CAML, then you can go and reserve the number.

 q.Query = "<Where><And><Geq><FieldRef Name=""StartTime"" /><Value IncludeTimeValue=""TRUE"" Type=""DateTime"">" + _
        Utilities.SPUtility.CreateISO8601DateTimeFromSystemDateTime(startTime) + _
        "</Value></Geq><Leq><FieldRef Name=""StartTime"" /><Value IncludeTimeValue=""TRUE"" Type=""DateTime"">" + _
        Utilities.SPUtility.CreateISO8601DateTimeFromSystemDateTime(endTime) + _
        "</Value></Leq></And></Where><OrderBy><FieldRef Name=""ID"" Ascending=""True"" /></OrderBy>"

q1.Query = "<Where><And><Geq><FieldRef Name=""EndTime"" /><Value IncludeTimeValue=""TRUE"" Type=""DateTime"">" + _
        Utilities.SPUtility.CreateISO8601DateTimeFromSystemDateTime(startTime) + _
        "</Value></Geq><Leq><FieldRef Name=""EndTime"" /><Value IncludeTimeValue=""TRUE"" Type=""DateTime"">" + _
        Utilities.SPUtility.CreateISO8601DateTimeFromSystemDateTime(endTime) + _
        "</Value></Leq></And></Where><OrderBy><FieldRef Name=""ID"" Ascending=""True"" /></OrderBy>"
+3
source

All Articles