1

I have an Add-In that works fine to install in an English setup of SharePoint. However, when I test this in another language I run into an issue.

The issue is with this code:

var list = web.get_lists().getByTitle("Style Library");

I get the error that the list "Style Library" can't be found on the site https://***.sharepoint.com/sites/Testsite.

In addition to this I also need the following to be language independent:

list.get_fields().getByTitle("Title");

How can I do this in another way without being language dependent? I've tried to search everywhere but can't find a way. Is this something to do with "Metadata Language"? Can that be changed for an Add-In?

2
  • Which language you are using for your SharePoint site? – Ganesh Sanap Feb 29 '20 at 13:59
  • On this specific site I'm using Swedish, but as this is an AddIn to be installed on several different sites I need this to work independently of the language. – moviaa Feb 29 '20 at 14:16
1

You can also get the SharePoint List/Library using GUID instead of its Title.

To get the list instance using GUID try below code:

var listGUID = "92BFE60B-147A-49CD-8C86-38CD90987235"; // This GUID is just for example
var list = web.get_lists().getById(listGUID);

SP.ListCollection.getById Method (sp.js).

You can find the GUID of your SharePoint List/Library by following the steps from any of the below links:

  1. Finding the Id (Guid) for a SharePoint List.
  2. Sharepoint Online Addin - Add item to list - CSOM

Note: The GUID for the Style Library will be different for all SharePoint sites (If you are planning to use this Add-in across multiple sites).

4
  • Thanks, is this an ID that is always the same for all Sharepoint sites, or something unique per site? – moviaa Feb 29 '20 at 14:15
  • No, this will not be the same for all SharePoint sites. – Ganesh Sanap Feb 29 '20 at 14:40
  • Maybe you can try using GetList method as mentioned here and here OR the workaround mentioned here to get the list using its URL. Let me know if this works for you. – Ganesh Sanap Feb 29 '20 at 14:51
  • There is not a way to get the list or field based on their "real" English name? So for instance "Site Library" or "Title", instead of their translated name? – moviaa Feb 29 '20 at 15:13
0

You can use getById(id) method.

var list = web.get_lists().getById(listId);

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.