[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

SPSERVICES

Posted on 2012-08-23
8
Medium Priority
?
852 Views
Last Modified: 2012-10-10
I was playing familiarizing myself with SPSERVICES by following the example on the following blog..

http://www.sharepointhillbilly.com/Lists/Posts/Post.aspx?List=9174cc90%2Dd85c%2D4f0b%2Da884%2D4c4023ff9556&ID=5&Web=70322961%2D8cf0%2D46cf%2Db4c4%2Daccdc264bf8e

I did everything exactly how it was done on the blog but, it does not work for me.  I don't get any errors either.  I added a couple of alert()'s and those poped up but nothing else.

Any ideas?

Attached is my code.
eeGetSpeakers.js
0
Comment
Question by:Isaac
  • 4
  • 2
6 Comments
 
LVL 44

Expert Comment

by:Rainer Jeschor
ID: 38326914
Hi,
you did not mention your SharePoint version but using SiteAsset library I assume SharePoint 2010.
Attached a modified version of your script.
I uploaded the complete script as TEXT file to the site asset library and added a content editor web part on a new page, configuring this text file as link source.
This one works on my machine ;-)

Main change:
1. Instead of document ready use the built in container / array _spBodyOnLoadFunctionNames (which will be executed internally on document ready function by function)
2. Instead of $ use jQuery to avoid conflicts
Reference:
http://www.stephanrocks.com/2011/10/05/_spbodyonloadfunctionnames-in-sharepoint-vs-jquerys-document-ready/

Important:
You would have to rename the list back - on my system the list is named EESpeakers.
And adjust the script src links.

HTH
Rainer
EE-SPService.txt
0
 
LVL 5

Author Comment

by:Isaac
ID: 38327210
I made the changes but it still does not work for me.  I don't get any errors either and my alerts go off.

Could it be because I'm in Office 365 SharePoint Online?
0
 
LVL 5

Author Comment

by:Isaac
ID: 38327327
I'm definiteley doing something wrong.  I added it to another server and same thing.
0
Cyber Threats to Small Businesses (Part 1)

This past May, Webroot surveyed more than 600 IT decision-makers at medium-sized companies to see how these small businesses perceived new threats facing their organizations.  Read what Webroot CISO, Gary Hayslip, has to say about the survey in part 1 of this 2-part blog series.

 
LVL 5

Author Comment

by:Isaac
ID: 38327370
Here's the code I'm using....

<script type="text/javascript" src="../SiteAssets/jquery.js"></script>
<script type="text/javascript" src="../SiteAssets/jquery.SPServices.min.js"></script>

<script type="text/javascript">
//this is where the script starts after the page is loaded
_spBodyOnLoadFunctionNames.push("GetSpeakers");

function GetSpeakers()
{
	alert("in getspeaker function");
        //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 = "Speakers";

        var fieldsToRead =     "<ViewFields>" +
                                "<FieldRef Name='Title' />" +
                                "<FieldRef Name='Blog' />" +
                                "<FieldRef Name='Picture' />" +
                            "</ViewFields>";
                            
        var query = "<Query>" +
                        "<Where>" +
                            "<Neq>" +
                                "<FieldRef Name='ID'/><Value Type='Number'>0</Value>" + 
                            "</Neq>" +
                        "</Where>" +
                        "<OrderBy>" + 
                            "<FieldRef Name='Title'/>" +
                        "</OrderBy>" +
                    "</Query>";

        //Here is our SPServices Call where we pass in the variables that we set above
        jQuery().SPServices({
                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 name = ($(this).attr("ows_Title"));
                            
                            //get the blog url, SharePoint stores a url in the form of <url><comma><description>
                            //We only want the <url>. To accomplish this we use the javascript "split" function
                            //which will turn <url><comma><description> into an array where the first element [0]
                            //is the url.   Catch all that? if you didn't this is another reason you should be
                            //a developer if you are writing JavaScript and jQuery :)
                            var blog = ($(this).attr("ows_Blog")).split(",")[0];
                            
                            //same thing as the blog, a picture is stored as <url><comma><alt text>
                            var pictureUrl = ($(this).attr("ows_Picture")).split(",")[0];
                            
                            //call a function to add the data from the row to a table on the screen
                            AddRowToTable(name,blog,pictureUrl);
                            
                        });                
                    }
        });

}


function AddRowToTable(name,blog,pictureUrl)
{
    jQuery("#speakerTable").append("<tr align='middle'>" + 
                                "<td><img src='" + pictureUrl + "'><br><a href='" + blog + "'>" + name + "</a></td>" +
                               "</tr>");
                                
}

</script>

<!-- table where our speaker rows will go -->
<table id="speakerTable"></table>

Open in new window

0
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 2000 total points
ID: 38328165
Hi,

you would have to debug this - in regards to SharePoint online it would probably by an authentication issue - the web service should exist.

To debug:
1. Alert the response
Between line 43 and 44 add an
alert(xData.responseText);

2. Use Fiddler
Use Fiddler (www.fiddler2.com) as proxy and capture the request. You should now see
- what is the response status (200=OK or 404 not found or 401 not authorized)
- what is the response content

Questions:
- Which jQuery version do you use?
- Which SPService version do you use?
- Do it have to be SPService or would the SharePoint Client object model be an alternative?

Thanks and KR
Rainer
0
 
LVL 5

Author Comment

by:Isaac
ID: 38329174
I get the error,

'xData' is undefined.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In case you ever have to remove a faulty web part from a page , add the following to the end of the page url ?contents=1
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

865 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question