SPServices and Webs Web Services

Mar 8, 2010 at 9:22 PM

This is sort of continuing discussion from SharePoint Overflow 

when running mydomain.com/_vti_bin/webs.asmx I am getting list of this available operations:

Webs

The following operations are supported. For a formal definition, please review the Service Description.

  • CreateContentType
  • CustomizeCss
  • DeleteContentType
  • GetActivatedFeatures
  • GetAllSubWebCollection
  • GetColumns
  • GetContentType
  • GetContentTypes
  • GetCustomizedPageStatus
  • GetListTemplates
  • GetWeb
  • GetWebCollection
  • RemoveContentTypeXmlDocument
  • RevertAllFileContentStreams
  • RevertCss
  • RevertFileContentStream
  • UpdateColumns
  • UpdateContentType
  • UpdateContentTypeXmlDocument
  • WebUrlFromPageUrl

And as I am missing there GetUserCollectionFromSite and other user related operations I guess that I will be unable to use SharePoint Web Services jQuery Library and its $().SPServices function. But correct me if I am wrong.

But still want to learn more so please, can you give me advice where to start? Hove to use SPServices Web Services to get web collection for example? Where to put the code? How to call the function? What parameters to use? How is output generated?

Thanks,

Michal

Thanks

Coordinator
Mar 8, 2010 at 9:41 PM

I added a comment on SharePoint Overflow as well, but you're just looking at the wrong Web Service. GetGroupCollectionFromSite is an operation in the Users and Groups Web Service, not Webs.

M.

Mar 9, 2010 at 9:59 AM

Hi Marc,

sorry, my bad, yes it makes sense, that for user and group relate operation you call different Web Service, so I should read more carefully docs next time. But still I am missing starting point, as on MSDN documentation there are examples in Visual Basic or C#, but no documentation on how to use this with jQuery. If i will follow examples on your site, should I place code into placeholder of site, lets use defaul.aspx, or i should create new blank site?

<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
<script type="text/javascript" language="javascript" src="/jQuery_Libraries/jquery-1.3.2.js"></script>
<script type="text/javascript" language="javascript" src="/jQuery_Libraries/jquery.SPServices-0.5.2.min.js"></script>
<script type="text/javascript">
waitMessage = "<table width='100%' align='center'><tr><td align='center'><img src='/_layouts/images/gears_an.gif'/></td></tr></table>";
$(document).ready(function() {
$("#WSOutput").html(waitMessage).SPServices({
	operation: "GetUserInfo",
	userLoginName: "DOMAIN\\name_surname",
	completefunc: function (xData, Status) {
		$("#WSOutput").html("").append("<b>This is the output from the GetUserInfo operation:</b>");
		$(xData.responseXML).find("User").each(function() {
			$("#WSOutput").append("<li>ID: " + $(this).attr("ID") + "</li>");
			$("#WSOutput").append("<li>Sid: " + $(this).attr("Sid") + "</li>");
			$("#WSOutput").append("<li>Name: " + $(this).attr("Name") + "</li>");
			$("#WSOutput").append("<li>LoginName: " + $(this).attr("LoginName") + "</li>");
			$("#WSOutput").append("<li>Email: " + $(this).attr("Email") + "</li>");
			$("#WSOutput").append("<li>Notes: " + $(this).attr("Notes") + "</li>");
			$("#WSOutput").append("<li>IsSiteAdmin: " + $(this).attr("IsSiteAdmin") + "</li>");
			$("#WSOutput").append("<li>IsDomainGroup: " + $(this).attr("IsDomainGroup") + "</li>");
			$("#WSOutput").append("<hr/>");
		});
	}
});
</script>


In code, where you are using userLoginName: "DOMAIN\\name_surname",   are here really two \\?
I've tried this example, browser informed me, that script is loading, but nothing happened after finish.
Please direct me, where to begin.
Thanks,
Michal
Coordinator
Mar 9, 2010 at 12:51 PM

Michal:

To do what you're looking to do, you're going to need to understand jQuery a bit.  My "wrappers" around the SharePoint Web Services makes it easier, but it's still going to be a chunk of work.

In the example above, you're putting the code in the right place.  I'm not sure where you snipped this from (I certainly recognize it as my handiwork), but it looks like an old example of how I call the GetUserInfo operation.  It looks like you are missing a closing }); for the (document).ready.  It also is trying to write into some object with an Id of WSOutput, which you may not have on your page.

M.

Mar 9, 2010 at 4:49 PM

Marc,

you are right, this code is from your documentation http://spservices.codeplex.com/wikipage?title=%24%28%29.SPServices&referringTitle=Documentation but agree that I am missing WSOutput on my site. I simply don't know where to start. I need some solution for getting list of around 670 users on set of around 184 sites/sub-sites all together. I had described what I've found so far as solution (mentioned on SharePoint Overflow site) used Data Juggler, but looking for something more elegant.

And using native SharePoint services looks fine, but need initial kick, where to start study. so could you provide me some direction, where to start? I will appreciate that.

Thanks,

Michal

Coordinator
Mar 10, 2010 at 2:41 AM

Erm.  This is one of those things where it's way beyond a simple question and more like "you should hire me to do this for you". Not trying to be a jerk about it, but I can't really tell you exactly how to do it without doing it, and it would tak a chunk of time.

The basic idea is (based on the little I understand about what you want to do) that you would use the Web Services to loop through the sites and pull out the user information for each.  I think that you can build a nice little solution for this.

M.

Mar 10, 2010 at 10:26 PM

Marc, thanks for be patient and answering my questions, I know, that my problem is quit complex and there is no easy solution. Lets forgot on all users. Will I be able to get list of all site and sub-sites within site collection? Lets use my example mysubdomain.mydomain.com and I have set of sites here mysubdomain.mydomain.com/sites/xyz and mysubdomain.mydomain.com/sites/xyz/aaa, mysubdomain.mydomain.com/sites/xyz/bbb, ... So for this could I use GetAllSubWebCollection operationfor this? Without any complicated wrapping of functions together? If so, could you provide example?

Thanks

Michal

Coordinator
Mar 11, 2010 at 9:23 PM

Michal:

Calling GetAllSubWebCollection by iteslef is pretty straightforward.  Here's some example code from my test environment:
http://www.sympraxisconsulting.com/Demos/Demo%20Pages/SPjQueryWebServices.aspx
To see what this outputs, you'll need a div with the id="demo".

$("demo").html(waitMessage).SPServices({
  operation: "GetAllSubWebCollection",
  completefunc: function (xData, Status) {
   var out = $().SPServices.SPDebugXMLHttpResult({
    node: xData.responseXML,
    outputId: "demo"
   });
   $("demo").html("").append("<b>This is the output from the GetAllSubWebCollection operation:</b>" + out);
  }
 });

M.

Mar 12, 2010 at 10:12 AM

Marc,

Thanks for being patient with me. I've tried your example above using following code:

<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">

<script type="text/javascript" language="javascript" src="/jQuery_Libraries/jquery-1.3.2.js"></script>
<script type="text/javascript" language="javascript" src="/jQuery_Libraries/jquery.SPServices-0.5.2.min.js"></script>
<script type="text/javascript">
waitMessage = "<table width='100%' align='center'><tr><td align='center'><img src='/_layouts/images/gears_an.gif'/></td></tr></table>";

$(document).ready(function() {

$("demo").html(waitMessage).SPServices({
  operation: "GetAllSubWebCollection",
  completefunc: function (xData, Status) {
   var out = $().SPServices.SPDebugXMLHttpResult({
    node: xData.responseXML,
    outputId: "demo"
   });
   $("demo").html("").append("<b>This is the output from the GetAllSubWebCollection operation:</b>" + out);
  }
 });

});
</script>
<div id="demo"></div>

Did I missed something, as I get no errors but no results as well. Tried it on top site level mysubdomain.mydomain.com/pagewithscrip.aspx and also on site mysubdomain.mydomain.com/sites/pagewithscrip.aspx level with same results.

Thanks, Michal

Coordinator
Mar 12, 2010 at 2:27 PM

Michal:

Do you see the waitMessage? (It only contains the gears image.)  Where did you put the div?  It need to be inside a container that makes sense.  Are you putting the script in a CEWP or into the page itself?

M. 

Mar 12, 2010 at 8:50 PM

Marc, DIV is right after script, but probably it;s wrong. I am putting script into code of pageinto PlaceHolderMain  not into the CEWP. Is that right oe should i use CEWP instead? I've created new basic page in SherePoint and edited it in SP Designer and moved from Doc library to root of site where default.aspx is. Thas it meater where the page is placed?

 

Thanks, Michal

Coordinator
Mar 12, 2010 at 10:02 PM

Putting the code into the page is what I recommend.  See the bottom of this page: http://spservices.codeplex.com/documentation

I think the issue is that you have the DIV in an untenable place. It needs to be within a TD or something.  Given the questions you are asking, try putting the code into a CEWP instead.  That'll put the DIV in a good spot.

M.

Apr 1, 2010 at 8:18 PM

I am trying something similar to this. I find it easier to use the CEWP when using jQuery. I am fairly novice at jQuery but i did notice in the previous example, that the # symbol was missing in the selector in order to append to the <div> tag using the id.

I had a question about modifing the output of this example. Would it be possible to populate a list or a drop-down using this GetAllSubWebCollection output?

 

Coordinator
Apr 2, 2010 at 9:31 PM

CodeRider:

Good catch! Sometimes it's the most obvious stuff that I don't see.

You can certainly create a list or dropdown with any type of values you want.  To do this with GetAllSubWebCollection, you might want to use the Web Service as the DataSource for a DVWP, though.  It'd be easier to get things set up.

M.