0

I am trying to get all list items of a sharepoint list using WebServices into a Windows 7 gadget, but I am not really sure how I can do that,

I find this code on google without any explanation, So I dont know how I will get the data of list using this code and then display in a Windows Gadget.

Can anyone guide me to the right direction please ?

Gadget.xml is

    <?xml version="1.0" encoding="utf-8" ?>
<gadget>
  <name>HelloGadget</name>
  <version>1.0.0.0</version>
  <description>Hello World Gadget.</description>
  <hosts>
    <host name="sidebar">
      <base type="HTML" apiVersion="1.0.0" src="first.html" />
      <permissions>Full</permissions>
      <platform minPlatformVersion="1.0" />
    </host>
  </hosts>
</gadget>

first.html is

    <html>
<script>
//----------------- resizes the gadget display surface
function DoInit() {
    document.body.style.width = 90;
    document.body.style.height= 55;
    document.body.style.margin=0;
}

    $(document).ready(function() 
{
    var soapEnv =
        "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> 
            <soapenv:Body> 
                 <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> 
                    <listName>ListName</listName> 
                    <viewFields> 
                        <ViewFields> 
                           <FieldRef Name='Title' /> 
                       </ViewFields> 
                    </viewFields> 
                </GetListItems> 
            </soapenv:Body> 
        </soapenv:Envelope>";

    $.ajax({
        url: "http://my_site/_vti_bin/lists.asmx",
        type: "POST",
        dataType: "xml",
        data: soapEnv,
        complete: processResult,
        contentType: "text/xml; charset="utf-8""
    });
});

function processResult(xData, status) {
    $(xData.responseXML).find("z\:row").each(function() {
        alert($(this).attr("ows_Title"));
    });
}

</script>
<body onload="DoInit();">
<table border="5"><tr><td><center><i>Hello World!</i></center></td></tr></table>
<div id = "clickit"> <button type="button" onclick="" >Click Me!</button> </div>
</body>
</html>

Cheers

Muhammad Raja
  • 1,970
  • 3
  • 28
  • 46

1 Answers1

0

We are all familiar with SQL. There is a new jQuery library called SPSQL. This is really cool because you can query SharePoint using SQL syntax. Just add the appropriate libraries and you are on your way. See the example below and article here.

To get items, just do the following:

var result = SPSql.parseSQL('SELECT MyList.Field FROM MyList WHERE MyList.ID > 10 ORDER BY  MyList.ID DESC');

Now it is possible to process all result rows:

for (var row = 0; row < result.length; row++) {
   for (var column in result[row])
      alert( column + ": " + result[row][column] );
 }
  • Hi Emmie, thanks for your answer, But where will i gonna provide URL or User credentials in this case :S – Muhammad Raja May 18 '12 at 08:42
  • It uses SPServices to automatically get the list based on the site you have this code. – Emmie Lewis-Briggman May 18 '12 at 09:01
  • It uses SPServices to automatically get the list based on the site you have this code. Will this code reside on a SharePoint site? If not then you will need to modify the javascript with this project to get the list items from a particular URL. I believe by default SPServices run under the current credentials of the SharePoint site. http://spservices.codeplex.com/ – Emmie Lewis-Briggman May 18 '12 at 09:09
  • Multiple lists that you want to use? – Emmie Lewis-Briggman May 18 '12 at 10:05
  • Nope, I just want to use just one List, but then how can i tell this code that I want this specific list :) – Muhammad Raja May 18 '12 at 10:06
  • You just pass in the list name for your select query like above. You will have the modify the javascript that comes with the plug in to point to a specific URL since this will not reside on a SharePoint site. I am going to test this out later today officially and give you some information about it. – Emmie Lewis-Briggman May 18 '12 at 10:08
  • One thing I need to mention again that I am using it in a Gadget, not sharepoint site – Muhammad Raja May 18 '12 at 10:36