Skip to main content

Get Event List Items CAML Query

 // Set webUrl and listGuid to values specific to your site and list

var webUrl = "http://server/sitewhereyourlistexists";
var listGuid = "{000000000-0000-0000-0000-000000000000}"

// An XMLHttpRequest object is used to access the web service
var xhr = new XMLHttpRequest();
var url = webUrl + "/_vti_bin/Lists.asmx";
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type","text/xml; charset=utf-8");
xhr.setRequestHeader("SOAPAction","http://schemas.microsoft.com/sharepoint/soap/GetListItems");

// The message body consists of an XML document 
// with SOAP elements corresponding to the GetListItems method parameters
// i.e. listName, query, and queryOptions
var data = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"+
    "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" + 
        "<soap:Body>" +
        "<GetListItems xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">" + 
                "<listName>"+listGuid+"</listName>" + 
                "<query>" + 
                    "<Query><Where>" +
                        "<DateRangesOverlap>" + 
                            "<FieldRef Name=\"EventDate\"/>"+
                            "<FieldRef Name=\"EndDate\"/>"+
                            "<FieldRef Name=\"RecurrenceID\"/>"+
                            "<Value Type=\"DateTime\"><Today/></Value>"+
                        "</DateRangesOverlap>"+
                    "</Where></Query>"+
                "</query>" +
                "<queryOptions>"+
                    "<QueryOptions>"+
                        "<ExpandRecurrence>TRUE</ExpandRecurrence>"+
                    "</QueryOptions>"+
                "</queryOptions>" +
        "</GetListItems>" +
        "</soap:Body>" +
    "</soap:Envelope>";

// Here we define what code we want to run upon successfully getting the results
xhr.onreadystatechange = function(){
    if(xhr.readyState == 4){
        if(xhr.status == 200){
            var doc = xhr.responseXML;
            // grab all the "row" elements from the XML results
            var rows = doc.getElementsByTagName("z:row");
            var results = "Today's Schedule ("+rows.length+"):\n\n";
            var events = {};
            for(var i = 0, len = rows.length; i < len; i++){
                var id = rows[i].getAttribute("ows_FSObjType"); // prevent duplicates from appearing in results
                    if(!events[id]){ 
                        events[id] = true;
                        var allDay = rows[i].getAttribute("ows_fAllDayEvent"),
                            title = rows[i].getAttribute("ows_Title"),
                            start = rows[i].getAttribute("ows_EventDate"); 
                        var index = start.indexOf(" "); 
                        var date = start.substring(5,index)+"-"+start.substring(2,4); // get the date in MM-dd-yyyy format
                        start = start.substring(index, index+6); // get the start time in hh:mm format
                        var end = rows[i].getAttribute("ows_EndDate"); 
                        index = end.indexOf(" "); end = end.substring(index,index+6); // get the end time in hh:mm format
                        results += date + " " + (allDay == "1" ? "All Day\t" : start + " to " + end ) + " \t " + title + "\n";
                    }
                }
                alert(results);
            }else{
                alert("Error "+xhr.status);
            }   
    }
};

// Finally, we actually kick off the query
xhr.send(data);

Comments

Popular posts from this blog

Event Date Function

  Date.toISOFormat = function (date, ignoreTime) {      /// <summary>Date object static method to format a date to date ISO string - YYYY-MM-DDThh:mm:ssZ</summary>      /// <param name="date" type="Date" mayBeNull="false" optional="false"></param>      /// <param name="ignoreTime" type="Boolean" mayBeNull="false" optional="true"></param>      /// <returns type="String">A string representing ISO format for specied date</returns>        // If not specified, time is ignored      var ignoreTime = ignoreTime || {};        function pad(number) {          // Add leading 0 if number is less then 10 (enclosed method)          var r = String(number);          if (r.length ==...

The _spPageContextInfo

I f you are creating a SharePoint app using JavaScript and the Client side object model you need this friendly object. In the development of an app, you would require some basic properties- SharePoint as a framework provides these with the  _spPageContextInfo  object. _  spPageContextInfo  will provide these below properties:  webServerRelativeUrl  webAbsoluteUrl siteAbsoluteUrl serverRequestPath layoutsUrl webTitle webTemplate tenantAppVersion isAppWeb webLogoUrl webLanguage currentLanguage currentUICultureName currentCultureName env nid fid clientServerTimeDelta updateFormDigestPageLoaded siteClientTag crossDomainPhotosEnabled webUIVersion webPermMasks pagePersonalizationScope userId userLoginName systemUserKey alertsEnabled siteServerRelativeUrl allowSilverlightPrompt themedCssFolderUrl themedImageFileNames

PublishingAssociatedContentType

The Content Type to be associated with a page layout is indicated by the 'PublishingAssociatedContentType'. In the actual sense it means a binding setting between the Page Layout and the content type. If you fail to provide one, the SharePoint framework will make use of the Page Content type. The format of the binding is: ';# e.g. ';#ContentPage;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900470b13dd348649d08f9e5151501df9a4000dbd46dad8d045f98c83ad983b66d3f2;#'. where Content Type name: ContentPage Content Type ID: 0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900470b13dd348649d08f9e5151501df9a4000dbd46dad8d045f98c83ad983b66d3f2 respectively. QED