Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a list called "Subscribed users" on the top level that has 3 columns storing a username, a name of a list or library, and an url to a page.

I use SPServices to look up if the current user is in that list, and if he/she is, I return the row details. In my test it does return a row since I checked it with the console (it returns my name, a name of a list called "TEST Documenten" and an url to a page).

When I do a console log of currentViewLLIB, it returns "TEST Documenten". When I do a console log of listLibraryName, it also returns "TEST Documenten". So basically both currentViewLLIB and listLibraryName return the same, yet when I use the currentViewLLIB in the second SPServices part it won't return any results whereas it does when I use listLibraryName.

I can't figure it out since both variables return the same value and one works while the other doesn't, I'm puzzled as to what might cause this.
Any idea on why this happens?

var USER = $().SPServices.SPGetCurrentUser({ 
        webURL: "", 
        fieldName: "Title", 
        fieldNames: {}, 
        debug: false
});

var currentViewUser;
var currentViewLLIB;
var currentViewPURL;

$().SPServices({
    operation: "GetListItems",
    async: false,        
    webURL: 'https://my-intranet-here.com/',
    listName: 'Subscribed users',
    completefunc: function (xData, Status) {
        $(xData.responseXML).SPFilterNode("z:row").each(function() {
            if ($(this).attr("ows_Title") == USER) {
                currentViewUser = $(this).attr("ows_Title");
                currentViewLLIB = $(this).attr("ows_ListLibID");
                currentViewPURL = $(this).attr("ows_PageURL");
                console.log('Found the current user!');
            }
        });
    }
});

console.log(currentViewUser);
console.log(currentViewLLIB);
console.log(currentViewPURL);

// This line works: 
//var listLibraryName = "TEST Documenten";

// This line does not work: 
var listLibraryName = currentViewLLIB;

$(function() {
$().SPServices({
        operation: "GetListItems",
        async: false,
        listName: listLibraryName,
        completefunc: function (xData, Status) {
            $(xData.responseXML).SPFilterNode("z:row").each(function() {
                var liHtml = $(this).attr("ows_ID");
                console.log(liHtml);
            });
        }
    });
});

Suggestions on what I should try are very welcome, your help is very much appreciated!

share|improve this question
    
Try replacing 'Subscribed users' With 'Subscribed_x0020_users' –  Ashish Feb 28 at 9:29
    
But "Subscribed users" is the name of the list, not the name of a column. I can perfectly fetch data from that list, it's the second SPServices that can't seem to work with currentViewLLIB (even though it has the exact same value as the listLibraryName I commented). –  Magali Feb 28 at 9:37
    
Why did you not specify webURL for the second function? Is the list in the same site? –  kmo Feb 28 at 9:39
    
The list isn't in the same site but I'm planning on replacing it with the GUID so that it wouldn't need the webURL. And since it worked at first (with the first value of listLibraryName) I didn't think it would need a webURL. –  Magali Feb 28 at 9:45
    
can You Just use single Quotes for 'listLibraryName' and try? –  Ashish Feb 28 at 10:09

1 Answer 1

up vote 1 down vote accepted

Found it!
Instead of just using the name of a list, I stored the GUID of the list in "Subscribed users" and fetched that one. I then unescape it using this:

unescape(currentViewLLIB);

I can now call the list in the second SPServices part. :)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.