0

I am attempting to reference a document library in JavaScript. From what I have read, I should be able to open the library using something similar to the following:

list = web.get_lists().getByTitle("Vacation  NonTravel Requests");

The problem here is that I cannot get the list via this request- rather, I receive the error List 'Vacation NonTravel Requests' does not exist at site with URL .... I assume this is because I am not dealing with the spaces properly, but when I navigate to the library, the URL shows it with spaces. Regardless, I have tried replacing them with _x0020_ as SharePoint seems to do with some field names (replacing the double space with _x0020__x0020_, _x0020_x0020_, and _x0020x0020_, each with no success), and I have tried simply removing the spaces. I'm not sure what to try next, or even if this is actually the reason for my error message. Has anyone dealt with this before?

EDIT: I have also tried replacing the spaces with %20, but still no luck

EDIT: As requested, following is all of the relevant code:

list = web.get_lists().getByTitle('Vacation  NonTravel Requests');
var collListItems2 = list.getItems(SP.CamlQuery.createAllItemsQuery());

context.load(collListItems2);
context.executeQueryAsync(
    function(){
        alert('success');
    },
    function(){alert('fail');}
);

Just before this, I have a similar query (on a list) that is working fine. I use collListItems2 here in case the issue has to do with the variable being in use, and I have created duplicates of both the context and the web variables for the same purpose.

1
  • Normally spaces in titles are not an issue, but I can't say I've ever dealt with a double space in a list name before. Your issue likely resides elewhere than in the one line of code you've supplied. Post your whole code block and you'll have a better chance of getting an answer. Jul 30, 2013 at 17:08

1 Answer 1

0

Well, it turns out it was a fairly simple problem. Although the URL listed the name of the list as Vacation NonTravel Requests, I had to use the display-name, which is Vacation / Non-Travel Requests. I had been under the impression that the internal name was the one to reference, not the display name. I guess that doesn't apply to library names.

2
  • The method being named getByTitle is a hint! Jul 30, 2013 at 19:14
  • Yeah, that makes sense. I was just confused by the fact that for field names, you have to use internal names rather than display names. I assumed that it was the same for lists / libraries.
    – Crash
    Jul 30, 2013 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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