shaneoss
Scout

Re: Check Calendar for Double Bookings

Hi @bdupree,

We have a resource called HotDesk which is a list lookup to another list on the site referencing a single line of text field on the list.

You can see in the code below in the CAML the resource (HotDesk) is added.

 

Easier to copy andpaste into Notepad++

 var startDate = NWF$("#" + StartTime).val();
 var endDate = NWF$("#" + EndTime).val();
 var hotDesk = NWF$("#" + HotDesk).val();
 if (startDate != "" && endDate != "" && hotDesk != "")
 {
  if (hotDesk.indexOf(";#") != -1)
  {
   var hotDeskval = hotDesk.split(";#");
   hotDesk = hotDeskval[1];
  }
  var startHours = NWF$('#' + StartTime).parent().find("select[id*='DateHours']").val(); 
  var startMinutes = NWF$('#' + StartTime).parent().find("select[id*='DateMinutes']").val();
  var endHours = NWF$('#' + EndTime).parent().find("select[id*='DateHours']").val();
  var endMinutes = NWF$('#' + EndTime).parent().find("select[id*='DateMinutes']").val();
  var isoStartDateStr = GetISODateString(startDate, startHours, startMinutes); 
  var isoEndDateStr = GetISODateString(endDate, endHours, endMinutes);
  var clientContext = SP.ClientContext.get_current();
  var web = clientContext.get_web();
  var list = web.get_lists().getByTitle('Region Hot Desks');
  var camlQuery = new SP.CamlQuery();
  var query = String.format("<View><Query><Where><And><Or><Or><And><Leq><FieldRef Name='EventDate' /><Value Type='DateTime' IncludeTimeValue='TRUE'>{0}</Value></Leq><Gt><FieldRef Name='EndDate' /><Value Type='DateTime' IncludeTimeValue='TRUE'>{0}</Value></Gt></And><And><Lt><FieldRef Name='EventDate' /><Value Type='DateTime' IncludeTimeValue='TRUE'>{1}</Value></Lt><Geq><FieldRef Name='EndDate' /><Value Type='DateTime' IncludeTimeValue='TRUE'>{1}</Value></Geq></And></Or><Or><And><Leq><FieldRef Name='EventDate' /><Value Type='DateTime' IncludeTimeValue='TRUE'>{0}</Value></Leq><Geq><FieldRef Name='EndDate' /><Value Type='DateTime' IncludeTimeValue='TRUE'>{1}</Value></Geq></And><And><Geq><FieldRef Name='EventDate' /><Value Type='DateTime' IncludeTimeValue='TRUE'>{0}</Value></Geq><Leq><FieldRef Name='EndDate' /><Value Type='DateTime' IncludeTimeValue='TRUE'>{1}</Value></Leq></And></Or></Or><Eq><FieldRef Name='Hot_x0020_Desk' /><Value Type='Text'>{2}</Value></Eq></And></Where></Query></View>", isoStartDateStr, isoEndDateStr, hotDesk);
  var currentItemID = GetUrlKeyValue("ID");
  if (currentItemID != "")
   query = String.format("<View><Query><Where><And><And><Or><Or><And><Leq><FieldRef Name='EventDate' /><Value Type='DateTime' IncludeTimeValue='TRUE'>{0}</Value></Leq><Gt><FieldRef Name='EndDate' /><Value Type='DateTime' IncludeTimeValue='TRUE'>{0}</Value></Gt></And><And><Lt><FieldRef Name='EventDate' /><Value Type='DateTime' IncludeTimeValue='TRUE'>{1}</Value></Lt><Geq><FieldRef Name='EndDate' /><Value Type='DateTime' IncludeTimeValue='TRUE'>{1}</Value></Geq></And></Or><Or><And><Leq><FieldRef Name='EventDate' /><Value Type='DateTime' IncludeTimeValue='TRUE'>{0}</Value></Leq><Geq><FieldRef Name='EndDate' /><Value Type='DateTime' IncludeTimeValue='TRUE'>{1}</Value></Geq></And><And><Geq><FieldRef Name='EventDate' /><Value Type='DateTime' IncludeTimeValue='TRUE'>{0}</Value></Geq><Leq><FieldRef Name='EndDate' /><Value Type='DateTime' IncludeTimeValue='TRUE'>{1}</Value></Leq></And></Or></Or><Neq><FieldRef Name='ID' /><Value Type='Integer'>{2}</Value></Neq></And><Eq><FieldRef Name='Hot_x0020_Desk' /><Value Type='Text'>{3}</Value></Eq></And></Where></Query></View>", isoStartDateStr, isoEndDateStr, currentItemID, hotDesk);
  camlQuery.set_viewXml(query);
  var listItems = list.getItems(camlQuery);
  clientContext.load(listItems);

First CAML (end):

<Eq><FieldRef Name='Hot_x0020_Desk' /><Value Type='Text'>{2}</Value></Eq></And></Where></Query></View>", isoStartDateStr, isoEndDateStr, hotDesk);

 

Second CAML (end):

<Eq><FieldRef Name='Hot_x0020_Desk' /><Value Type='Text'>{3}</Value></Eq></And></Where></Query></View>", isoStartDateStr, isoEndDateStr, currentItemID, hotDesk);

 

Note there's the additional <And> at the beginning accompanying the closing tag.

 

If you needed to add additional resources say up to three you'd need to update the queries to include your additional fields.

 

Hope this helps. :)

Reply
llyehock
Scholar

Re: Check Calendar for Double Bookings

Hi Shaneoss,

we tried your JS within our On premise farm, however the form just stuck there keep loading the form will not appear, wonder how to resolve this?

0 Kudos
Reply