This project has moved and is read-only. For the latest updates, please go here.

Launcher for custom view

Jul 31, 2012 at 4:46 PM

I'm trying to make a dynamic custom view by using SPService !!


First I did it like this :



	function GetSpeakers()
        //The Web Service method we are calling, to read list items we use 'GetListItems'
        var method = "GetListItems";
        //The display name of the list we are reading data from
        var list = "leave application";

        //We need to identify the fields we want to return. In this instance, we want the Name (Title),
        //Blog, and Picture fields from the Speakers list. You can see here that we are using the internal field names.
        //The display name field for the Speaker's name is "Name" and the internal name is "Title". You can see it can 
        //quickly become confusing if your Display Names are completely differnt from your internal names. 
        //For whatever list you want to read from, be sure to specify the fields you want returned. 
        var fieldsToRead =     "<ViewFields>" +
                                "<FieldRef Name='Title' />" +
                                "<FieldRef Name='Period_x0020_of_x0020_leave_x002'/>" +
								"<FieldRef Name='Period_x0020_of_x0020_leave_x0020'/>" +
								"<FieldRef Name='Period_x0020_of_x0020_leave_x0021'/>" +
								"<FieldRef Name='Period_x0020_of_x0020_leave_x0022'/>" +
								"<FieldRef Name='Period_x0020_of_x0020_leave_x0023'/>" +
								"<FieldRef Name='Period_x0020_of_x0020_leave_x0024'/>" +
								"<FieldRef Name='StartDate'/>" +
								"<FieldRef Name='EndDate'/>" +
								"<FieldRef Name='Approved'/>" +
								"<FieldRef Name='Office'/>" +
								"<FieldRef Name='ID'/>" +
        //this is that wonderful CAML query I was talking about earlier. This simple query returns
        //ALL rows by saying "give me all the rows where the ID field is not equal to 0". I then 
        //tell the query to sort the rows by the Title field. FYI: a blank query ALSO returnsoogle
        //all rows, but I like to use the below query because it helps me know that I MEANT to 
        //return all the rows and didn't just forget to write a query :)
        var query ="<Query>" +
					"<Where>" +
					"<Eq>" +
						"<FieldRef Name='Approved'/>" +
						"<Value Type='Text'>Approved L2</Value>" +
					"</Eq>" +
						"</Where>" +
						"<OrderBy><FieldRef Name='Office'/><FieldRef Name='Title'/></OrderBy>" +
				"</Query>" ;


        //Here is our SPServices Call where we pass in the variables that we set above
                operation: method,
                async: false,  //if you set this to true, you may get faster performance, but your order may not be accurate.
                listName: list,
                CAMLViewFields: fieldsToRead,
                  CAMLQuery: query,
                      //this basically means "do the following code when the call is complete"
                    completefunc: function (xData, Status) { 

                        //this code iterates through every row of data returned from the web service call
                        $(xData.responseXML).SPFilterNode("z:row").each(function() { 
                            //here is where we are reading the field values and putting them in JavaScript variables
                            //notice that when we read a field value there is an "ows_" in front of the internal field name.
                            //this is a SharePoint Web Service quirk that you need to keep in mind. 
                            //so to read a field it is ALWAYS $(this).attr("ows_<internal field name>");
                                                   //get the title field (Speaker's Name)
                            var titre=($(this).attr("ows_Title"));

 var per1From=($(this).attr("ows_Period_x0020_of_x0020_leave_x002")); var per1To=($(this).attr("ows_Period_x0020_of_x0020_leave_x0020")); var per2From=($(this).attr("ows_Period_x0020_of_x0020_leave_x0021")); var per2To=($(this).attr("ows_Period_x0020_of_x0020_leave_x0022")); var per3From=($(this).attr("ows_Period_x0020_of_x0020_leave_x0023")); var per3To=($(this).attr("ows_Period_x0020_of_x0020_leave_x0024")); var startDate=($(this).attr("ows_StartDate")); var endDate=($(this).attr("ows_EndDate")); var id = ($(this).attr("ows_ID")); var office = ($(this).attr("ows_Office"));

So I launch the SPService by using the spbodyonloadfunctionnames.push and it works !!


After I'm using the same function GetSpeakers, but i launch the function with a button :

function calcul()


And it launch my GetSpeakers function, but I can see the 

alert(xData.responseText); (with good result) but after nothing !!!

The program stop .... and I really don't understand why !!

Any idea ?

Aug 1, 2012 at 10:54 AM

I try with

var out = $().SPServices.SPDebugXMLHttpResult({
					node: xData.responseXML

And I have this response when I call the GetSpeakers with an other function


0 xmlns:soap
1 xmlns:xsi
2 xmlns:xsd
0 xmlns

There is no response ....

Aug 1, 2012 at 3:08 PM

I would suggest removing your filter to see if you get an items returned then. It may be that your filter value is incorrect. While SPDebugXMLHttpResult can be helpful, you should also learn to use Fiddler or Firebug to look at the Net traffic so that you can see if there is any addional information that SPDebugXMLHttpResult isn't displaying.