0

I am currently working on SharePoint 2010 farm and trying to create calendar for our organisation's meeting rooms.

We have 5 meeting room and want separate calendar for each rooms. In the calendar i don't want any booking to conflict with each other. i have searched every where and found nothing.

Is there any way to prevent this issue? or is it better to create locations in exchange server and import the exchange calendar into the SharePoint calendar?

  • create a resource mailbox in exchange and link this to sharepoint – ozhug Feb 12 '15 at 3:57
  • Sathiya did you find a solution to this? Regards Moses – b5ml May 12 '15 at 10:05
  • Not yet Moses, but still its a challenging task. – Sathiya May 13 '15 at 8:46
1

Try using your calendar to act as a "Resource Reservation" calendar.

this will help you in preventing the double booking problem

go through the Link

Other thing which you can do is that if you are using custom coded solution than you can check for the condition in a CAML query instead.

this link goes through the same method

another option to this will be if you use javascript or JSLink for your solution.

| improve this answer | |
1

Here's a custom JavaScript solution. It requires moment.js for date parsing and also jQuery for DOM manipulation/handling events so you will need to reference both of those in the calendar forms that you customize. In my situation, I included this solution inside a custom new form and custom edit form that I created using SharePoint Designer 2010 for a default Calendar list.

To use it, you will need to update the three items I've wrapped in double !!'s (remove the !!'s too) and you will need to add the classes (i.e. .allday, .starttime, .endtime) to the relevant .ms-formbody TD elements within your custom forms' HTML so that events can be handled. You will also need to add a 'conflictingevents' UL element inside your form in order to append the message mentioned below (i.e. <ul id="conflictingevents"/>) where desired. I have mine underneath the drop-down option for the rooms.

This version is designed for event booking with multiple rooms in mind so if you'd like to simplify it to remove this capability just remove the if (xhrRoom == userRoom) { statement and closing curly brace }.

So, here's how it works.. if a user tries to schedule an event during the time frame of an existing event, a message showing the conflicting events date/times will show on the #conflictingevents element and the save button in the toolbar of the form will be hidden. The save button at the bottom of the form will also be disabled. If there is no conflict, the message is not shown and the save buttons are functional.

I realize this is an old post but I hope it may still help you or maybe someone else out there who comes across this!

EDIT: I realized after I posted this that you might be using multiple calendar lists (one for each room). The solution I posted is designed to work with one calendar list and support multiple rooms therein although it could be easily leveraged to support multiple queries across multiple calendar lists. In my experience, I've seen users simply create separate calendar views for a single calendar list if they wanted to display unique data in each view such as only showing events for a single room. Hope this still helps!

$(document).ready(function () {

    function doubleBooking() {

        // remove previous results if any (to avoid duplicate appends)
        $("ul#conflictingevents li").each(function () {
            $(this).remove();
        });

        // gather the values from start and end date/time fields that the user selects for comparison with existing event dates/times in the calendar list
        function parseSelectedDate(el) {

            var startTimeDateArr = $(el + " input").val().split("/"),
                startTimeDateArr1Parsed = parseInt(startTimeDateArr[1]);
            if (startTimeDateArr1Parsed < 10) { startTimeDateArrDay = "0" + startTimeDateArr1Parsed.toString() } else { startTimeDateArrDay = startTimeDateArr1Parsed.toString() };
            var startTimeDate = startTimeDateArr[2] + "-" + startTimeDateArr[0] + "-" + startTimeDateArrDay;

            var startTimeHour = $(el + " select").val() || "",
                startTimeHourArr = startTimeHour.split(" ") || "",
                startTimeMin = $(el + " [id*=DateTimeFieldDateMinutes]").val() || "";

            var startTime = startTimeDate + " " + startTimeHourArr[0] + ":" + startTimeMin + startTimeHourArr[1],
                selDate = moment(startTime, ["YYYY-MM-DD HH:mm" + "A"]).format("YYYY-MM-DD HH:mm:ss");

            var a = selDate.split(" "),
                d = a[0].split("-"),
                t = a[1].split(":"),
                date = new Date(d[0], (d[1] - 1), d[2], t[0], t[1], t[2]);

            var selDateObj = new Date(date);
            return selDateObj;

        }

        userEventStartTime = parseSelectedDate(".starttime");
        userEventEndTime = parseSelectedDate(".endtime");

        var soapEnv =
            "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
                <soapenv:Body> \
                        <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                        <listName>!!insert list name here!!</listName> \
                        <viewName>{!!insert view GUID here!!}</viewName> \
                    </GetListItems> \
                </soapenv:Body> \
            </soapenv:Envelope>";

        $.ajax({
            url: "!!insert path to your site here!!/_vti_bin/lists.asmx",
            type: "POST",
            dataType: "xml",
            data: soapEnv,
            complete: processResult,
            contentType: "text/xml; charset=\"utf-8\""
        });

        function processResult(xData, status) {

            var resultsArr = [];

            $(xData.responseXML).find("z\\:row, row").each(function () {                        

                var userTitle = $(".title input").val() || "";

                var xhrRoom = $(this).attr("ows_Room"),
                    userRoom = $(".room select").val() || "",
                    xhrTitle = $(this).attr("ows_Title");

                if (xhrRoom == userRoom) {

                    var xhrStartTime = $(this).attr("ows_EventDate");
                        xhrEndTime = $(this).attr("ows_EndDate");

                    var xhrStartTimeParsed = moment(xhrStartTime).format("YYYY-MM-DD HH:mm:ss");
                        xhrEndTimeParsed = moment(xhrEndTime).format("YYYY-MM-DD HH:mm:ss");

                    var a = xhrStartTimeParsed.split(" "),
                        d = a[0].split("-"),
                        t = a[1].split(":"),
                        xhrStartTimeParsedSplit = new Date(d[0], (d[1] - 1), d[2], t[0], t[1], t[2]);

                    var a = xhrEndTimeParsed.split(" "),
                        d = a[0].split("-"),
                        t = a[1].split(":"),
                        xhrEndTimeParsedSplit = new Date(d[0], (d[1] - 1), d[2], t[0], t[1], t[2]);

                    var xhrStartTimeParsedDateObj = new Date(xhrStartTimeParsedSplit),
                        xhrEndTimeParsedDateObj = new Date(xhrEndTimeParsedSplit);

                        // compare with values user has selected for date/time                   
                    if (userTitle != xhrTitle) {
                        if (userEventStartTime >= xhrStartTimeParsedDateObj && userEventStartTime < xhrEndTimeParsedDateObj // if user specfied start time starts after (or at) existing event start time but starts before existing event ends
                            || userEventEndTime > xhrStartTimeParsedDateObj && userEventStartTime < xhrEndTimeParsedDateObj) { // OR if user specified end time is after existing event begins but user event starts before existing event ends

                            // create li for messsage
                            resultsArr.push("<li>" + xhrTitle + " scheduled from " + moment(xhrStartTime).format("MMMM Do, YYYY h:mma") + " to " + moment(xhrEndTime).format("MMMM Do, YYYY h:mma") + "<br><br></li>");

                        } else if ($(".allday input").prop("checked")) {

                            // for when user checks 'all day'
                            var userEventStartTimeAllDay = parseSelectedDate(".starttime"),
                                userEventStartTimeStr = userEventStartTimeAllDay.toString();

                            var xhrStartTimeParsedDateObjStr = xhrStartTimeParsedDateObj.toString();

                            var userDateSubString = userEventStartTimeStr .slice(0,10),
                                xhrDateSubString = xhrStartTimeParsedDateObjStr.slice(0,10);

                            if (userDateSubString == xhrDateSubString) {
                                // create li for messsage
                                resultsArr.push("<li>" + xhrTitle + " scheduled from " + moment(xhrStartTime).format("MMMM Do, YYYY h:mma") + " to " + moment(xhrEndTime).format("MMMM Do, YYYY h:mma") + "<br><br></li>");                         
                            }                           
                        } 
                    }

                }

            });

            // append results to DOM
            if (resultsArr.length > 0) {

                // append and show conflicts element since there are some
                for (i = 0; resultsArr.length > i; i++) {
                    $("ul#conflictingevents").append(resultsArr[i]);
                }
                $("ul#conflictingevents").show();

                // remove save button from toolbar and disable form save button(s)
                $("[id*=Publish]").hide();
                $("[id*=savebutton]").each(function() {
                    $(this).attr("disabled", "");
                });

            } else {

                // hide conflicts element since there are none
                $("ul#conflictingevents").hide();

                // add save button to toolbar and enable form save button(s)
                $("[id*=Publish]").show();
                $("[id*=savebutton]").each(function() {
                    $(this).removeAttr("disabled");
                });

            }

        }

    } // end doubleBooking()

    // attach to events 
    $(".starttime input, .endtime input").blur(function () {
        doubleBooking();
    });

    $(".allday input").click(function() {
        doubleBooking();    
    });

    $(".starttime select, .endtime select").each(function () {
        $(this).change(function () {

            // the timeout takes into consideration SharePoint's default behavior of automatically updating the end time when the start time is adjusted
            // without this the correct end time will not be used for checking double booking
            setTimeout(function() {
                doubleBooking();
            }, 1000);       

        });
    });

    $(".room select").change(function () {

        // check for double booking
        doubleBooking();

    });

    // also run on page load
    doubleBooking();

});
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.