webURL on GetListItems. What's the secret?

Feb 5, 2012 at 3:06 AM

I'm new to spservices and have made some pretty significant improvements on my site in a short time.  Love it..., but... Can someone help me understand the webURL argument on GetListItems?  I am using this block of code below for navigation. I'm using listName a GUID since it didn't appear to function properly as i went from site to sub-site.  Here is the code that works perfectly:

$(document).ready(function() {
  $().SPServices({
    operation: "GetListItems",
    async: false,
    listName: "{23BB2DDE-4EEF-47B1-BD20-7EFE2D99D0D4}",
    CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='URL' /><FieldRef Name='RoutingRuleDescription' /></ViewFields>",
    completefunc: function (xData, Status) {
      $(xData.responseXML).SPFilterNode("z:row").each(function() {
          var title = ($(this).attr("ows_Title"));
          var href = ($(this).attr("ows_URL")).split(",")[0];
          var descr = ($(this).attr("ows_RoutingRuleDescription"));
          var target = ($(this).attr("ows_target"));
         
        var liHtml = "<li><a href='"+ href +"' title='"+descr+"' target='"+target+"'>" + title + "</a></li>";
        $("#colinks").append(liHtml);

      });
    }
  });
});

This is on the master page of my intranet web application. Now, I have 2 other web applications: one for search, and one for people.  Each of these web applications has their own master page as well.  When I <ctrl>+<c> | <ctrl>+<v> the code into the master page it doesnt work (as expected) since the list that holds the items only exists on the intranet web application.  I found the webURL argument and it looked like my solution.  Yet, I can't ever get it to work correctly.  Here is my busted code:

$(document).ready(function() {
 // From Search.company.com
  $().SPServices({
      operation: "GetListItems",
    async: false,
    webURL: "http://intranet.company.com/",
    listName: "{23BB2DDE-4EEF-47B1-BD20-7EFE2D99D0D4}",
    CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='URL' /><FieldRef Name='RoutingRuleDescription' /></ViewFields>",
    completefunc: function (xData, Status) {
      $(xData.responseXML).SPFilterNode("z:row").each(function() {
          var title = ($(this).attr("ows_Title"));
          var href = ($(this).attr("ows_URL")).split(",")[0];
          var descr = ($(this).attr("ows_RoutingRuleDescription"));
          var target = ($(this).attr("ows_target"));
        var liHtml = "<li><a href='#'>Here</a></li>";
        $("#colinks").append(liHtml);
      });
    }
  });
});

 

I have tried every possibility, permutation, and combination I can think of to make this work. with/without trailing slash, with/without protocol, list name/list GUID, AAM paths/servername:port/dns entries for the site, etc.  I even tried just putting it into a standalone app outside of SharePoint and seeing if I could get the data to return.  The only sucess I've seen is when i use it on the same webapp/site collection as the list.  I have also done the alert(); dance to see what gets fired, and what does not.  The part inside the .each(function(){ loop never executes with exception to the intranet web app.  Any thoughts on helping with trouble shooting? It almost appears to be a perms problem, but I don't even know how to prove that.  All three of the sites use nt security and are in my trusted zone so there is no login for the users. I've looked through the docs for help and found a few leads, but nothing to remedy the issue. Any thoughts? Any help would help.  Great product Marc. Thanks for the effort!

Thanks.

Feb 5, 2012 at 9:50 AM

webUrl is case sensitive as is all of javascript. Be sure that it is webUrl and not webURL as this will not work.

Dan

Feb 5, 2012 at 12:21 PM

Thanks SPEvilG for the quick response. I've seen it written both webURL and webUrl.  Its good to know which I am supposed to be using!  I changed my code but i am however, still not getting the results I'd hoped for.  I found another post in the documents that showed to alert the xml:

alert(xData.responseXML.xml);

I've added this to my code and can see a lot more of what is going on.  When added it told me the list didn't exist.  After some trouble shooting I have found no matter what I set the webUrl argument to it always uses the web app I am on.  When I run the GetListCollection method I get the lists for the site the master page is on, not for the site specified in the webUrl.  When I GetListItems on the pages library, I get them for 'Search' not 'Intranet'.  This is my current code:

 

$(document).ready(function() {

  $().SPServices({
      operation: "GetListItems",
    webUrl: 'http://intranet.company.com/',
    listName: "Pages",
    CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='URL' /><FieldRef Name='RoutingRuleDescription' /></ViewFields>",
    completefunc: function (xData, Status) {
    alert(xData.responseXML.xml);   
      $(xData.responseXML).SPFilterNode("z:row").each(function() {
          var title = ($(this).attr("ows_Title"));
        var liHtml = "<li><a href='#'>"+title+"</a></li>";
        $("#colinks").append(liHtml);

      });
    }
  });
});

Even though it specified to pull from http://intranet.company.com, it pulls from http://search.company.com.  I've tried different name equivalents in here (server:port, aam names, etc) and even tried http://spevilgenius.company.com.  It appears as if it is disregarding the value.  Does it have to be in a specific order? Does it need to be set last or something?

again, thanks for the feedback. You've got me going down the right path.

Feb 5, 2012 at 12:29 PM

If I read this right, I think you are going to run into issues. The webservices run in the context of the current user and they run based on the site context or where the actual .asmx files are located. Where are you trying to run the code exactly and what is the end goal? You keep saying web application and I wonder if you are in fact trying to cross web applications.

Feb 5, 2012 at 12:50 PM

I think you are reading this right.  I have 3 SharePoint Web Applications:

intranet.company.com
search.company.com
people.company.com

They all have similar global navigation along the top. One of those common elements is a list of company links. That list of company links lives at intranet.company.com/lists/company links.  The navigation on intranet.company.com works like a champ (I presume since the list lives there).  When I tried to get the list through either of the other 2 web applications I can't see the list.  is crossing web applications not allowed? if not, is there a better approach to my situation?  For some reason I thought I would be able to accomplish even from a standalone .net application that used the spservices library. is that not the case either?

Feb 5, 2012 at 2:42 PM

I just don’t think that is going to work that way. And the webservices run based on the logged in user to the SharePoint site. Maybe possible, but I don’t think so.

From: ScotyB [email removed]
Sent: Sunday, February 05, 2012 8:51 AM
To: evilgenius@cox.net
Subject: Re: webURL on GetListItems. What's the secret? [SPServices:293481]

From: ScotyB

I think you are reading this right. I have 3 SharePoint Web Applications:

intranet.company.com
search.company.com
people.company.com

They all have similar global navigation along the top. One of those common elements is a list of company links. That list of company links lives at intranet.company.com/lists/company links. The navigation on intranet.company.com works like a champ (I presume since the list lives there). When I tried to get the list through either of the other 2 web applications I can't see the list. is crossing web applications not allowed? if not, is there a better approach to my situation? For some reason I thought I would be able to accomplish even from a standalone .net application that used the spservices library. is that not the case either?

Coordinator
Feb 6, 2012 at 1:01 PM

First thing, the option is "webURL", as is clearly noted in the docs. As Dan mentions, capitalization matters. If you're seeing it spelled a different way in the documentation somewhere, please let me know.

webURL: 'http://intranet.company.com/'

ought to work, assuming that the authorization works. Auth is usually the issue when going across Web Apps, but there are many other things that can get in the way. I've seen so much variation in network topologies that I can't even list them all, and there's no way for SPServices to address them all.

M.

Feb 6, 2012 at 1:36 PM

Thanks for the clarification Marc. The discrepancies I've seen have been across other blogs not within the documentation on this site.  I'm going to get back at it again today now that I am in the office and not using the VPN and see if the results are different.  I sincerely appreciate both y'all's help in this.  It is good to hear that it should work.

Apr 11, 2012 at 7:32 PM

Did you ever solve this?

I am looking to do practically the exact same thing, and encountering the same problem.  I have made sure that the list in question is granting "Read" access to both "All Authenticated Users" and also "NT AUTHORITY\Authenticated Users", yet still the content is only retrived successfully and displayed in the global navigation from within the same site collection (intranet.company.com, or any of its children), but not from other site collections (such as search.company.com or people.company.com).

Apr 11, 2012 at 8:51 PM

Found it!

Answer I needed was in this post:  http://spservices.codeplex.com/discussions/347000

 

Apr 12, 2012 at 3:19 AM

No drasmu, I never got this to work for me on my web applications.  The list I am using only has 10-12 items in it used for global navigation. It was just easier for me to duplicate the list on multiple web apps than it was to figure it all out. :(  The answer in your post looks like it might work for me... I might give er another go when I have some more spare time. ;)  Glad you got yours working.