SPListNameFromUrl clarification

Jul 3, 2013 at 6:13 PM
Can I do this?
$().SPServices({
        operation: "SPListNameFromUrl",
        listName: listurl,
        async: false,
        completefunc: function(xData, Status) {
            console.log('here');
        }});
When I try to do that, I get :

SCRIPT5007: Unable to get value of the property '0': object is null or undefined
jquery.SPServices-0.7.2.min.js, line 19 character 7590

This works just fine, but is not very synchronous-y
 var j = $().SPServices.SPListNameFromUrl(listurl);
    console.log(listurl + ": " + j);
TIA
-John
Jul 5, 2013 at 7:47 PM
Actually, i found a little bug which was causing the SCRIPT5007.

Nevertheless, i still can't get this to work:

var j = $().SPServices.SPListNameFromUrl("http://sharepoint/Sales%20Operations/Lists/SalesArea%20List/");
it always returns the GUID of the current list, not the one I want ('SalesArea List')

TIA
Jul 5, 2013 at 7:58 PM
The documentation (here: http://spservices.codeplex.com/wikipage?title=$().SPServices.SPListNameFromUrl)
Says that you can give it 1 input param listName, although there is no example, and I don't have the source in available to now, I would assume the usage as follows:

var j = $().SPServices.SPListNameFromUrl({listName: "http://sharepoint/Sales%20Operations/Lists/SalesArea%20List/"});
Try that. 
_____
Paul

Sent from mobile device.

Jul 5, 2013 at 8:47 PM
Edited Jul 5, 2013 at 8:49 PM
Thanks for the reply Paul!
  • Youre code definatley affected change. However, the variable j is now getting set to the list name ... not the guid. The method name is SPListNameFromUrl, but the documentation says it will return the guid. The guid of the current list is returned when i send in a bad url value. (my code)
When I use your code, the variable j is set to the Name of the list i am targeting, but not the guid.

Here is my updated code inside a loop of listurl(s)
var j = $().SPServices.SPListNameFromUrl({listName: "http://sharepoint/Sales%20Operations/Lists/SalesArea%20List/"});
console.log(listurl + ": " + j);
Here is what is written to the console:
LOG: http://sharepoint/Sales%20Operations/Lists/JohnSmith/: http://sharepoint/Sales%20Operations/Lists/SalesArea%20List/ 
As you can maybe tell, i have a master List of listnames that i want to iterate through and figure out the GUIDs each. Then do GetListItems of each....
Jul 5, 2013 at 10:59 PM
Lets see what Marc says regarding name vs GUID.

I assume that you can't use the name I your use case, for same reason (maybe you don't know the webURL)?
_____
Paul

Sent from mobile device.
Jul 8, 2013 at 2:39 PM
Thanks Paul.

The list names tend to have all sorts of goofy characters so if this can work, it will be better than trying to outsmart the list's names...
Coordinator
Jul 9, 2013 at 3:04 AM
John:

SPListNameFromUrl is a function I built early on to determine the list context. It works by looking at the current URL and figuring out what list we're working with. It's not built to accept any other URL, thus no sign of that in the docs.

Some people were putting their list forms in places outside the list context (e.g., not in /Lists/listname or /libname) so I added the ability to pass in the list name so that the function would accept that value and not try to work out the context from the URL.

Finally, in 2010 and 2013, there are JavaScript variables which contain this info, so I use them to set the context instead.

M.
Jul 9, 2013 at 2:25 PM
Thanks for the replay Marc, and super thanks for SPServices!!

What I do now since all of my target lists are within the same SPWEB is:
  1. on $().ready call GetListCollection and on success,
  2. fill up a javascript object as such:
 ListOfListGUIDs[$(this).attr("Title")] = $(this).attr("ID");
later, when I am looping through the target lists and I want the list guid I just do this:
  var j = ListOfListGUIDs[listurl];
Thanks again,
J
Coordinator
Jul 9, 2013 at 3:00 PM
Worst case with SPListNameFromUrl is that it makes a single call to get the list's GUID (I'm assuming that you're on 2007, as in 2010 or 2013 that call won't even occur). You've replaced that with your own call, so from a performance perspective, the impact should be identical.

BTW, you can use list names and GUIDs interchangeably in many of the Web Services calls.

M.