Working in a bilingual environment brings his amount of problem. One of those is to be able to query a list based on its URL instead of its name. For example, if I query a list like this :
By querying all the SPListCollection of a precise SPWeb, I can make it work, but I was wondering if I could make it work with a better approach.
Here is what I built :
Thanks !
$().SPServices({
operation: "GetListItems",
async: true,
cache: false,
listName: "Shared Documents",
CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>",
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function() {
alert($(this).attr("ows_Title"));
});
}
});
I will only get my results when MUI is in English. In French, that will not work because the list name is "Documents partagés". So I need a way to query GetListItems with a List Guid. That guid is autogenerated when the site is created, so I can't rely on a fixed guid in my JS code. The only thing that I know that will not change is its URL.By querying all the SPListCollection of a precise SPWeb, I can make it work, but I was wondering if I could make it work with a better approach.
Here is what I built :
function GetListIdByUrl(listRootFolderUrl)
{
var listId = EMPTY_GUID;
if(!listRootFolderUrl.startsWith("/"))
{
listRootFolderUrl = "/" + listRootFolderUrl;
}
if(!listRootFolderUrl.endsWith("/"))
{
listRootFolderUrl = listRootFolderUrl + "/";
}
$().SPServices({
operation: "GetListCollection",
async: false,
cached: true,
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("List").each(function() {
var webUrl = $(this).attr("WebFullUrl");
var defaultViewUrl = $(this).attr("DefaultViewUrl");
var listUrl = defaultViewUrl.replace(webUrl, "");
if(listUrl != "")
{
if(listUrl.startsWith(listRootFolderUrl))
{
listId = $(this).attr("ID");
}
}
});
}
});
return listId;
}
Do you see any concern on using GetListCollection ? How can I improve that piece of code ?Thanks !