I know how to use lists.asmx?op=GetListAndView
to get list and view details.
I'm trying to do the same using CSOM. And, to keep it efficient, I wanted to make one call for multiple lists/views. But there is a possibility that a list or view doesn't exist so I should be able to check that for each list/view.
This is what I have so far.
var listsToCheck = [
{ "listName" : "....", "listGUID" : "....", "viewName" : "....", "viewGUID" : "...." },
{ "listName" : "....", "listGUID" : "....", "viewName" : "....", "viewGUID" : "...." },
{ "listName" : "....", "listGUID" : "....", "viewName" : "....", "viewGUID" : "...." },
{ "listName" : "....", "listGUID" : "....", "viewName" : "....", "viewGUID" : "...." },
{ "listName" : "....", "listGUID" : "....", "viewName" : "....", "viewGUID" : "...." }
];
ExecuteOrDelayUntilScriptLoaded(function()
{
var clientContext = SP.ClientContext.get_current();
for(var i = 0; i < listsToCheck.length; ++i)
{
var listToCheck = listsToCheck[i];
listToCheck.list = clientContext.get_web().get_lists().getByTitle(listToCheck.listName);
clientContext.load(listToCheck.list);
clientContext.load(listToCheck.list, 'EffectiveBasePermissions');
listToCheck.view = listToCheck.list.get_views().getByTitle(listToCheck.viewName);
clientContext.load(listToCheck.view);
}
clientContext.executeQueryAsync(Function.createDelegate(this, function()
{
// SEE NOTE BELOW
for(var i = 0; i < listsToCheck.length; ++i)
{
var listToCheck = listsToCheck[i];
console.log("user has edit permission: " + listToCheck.list.get_effectiveBasePermissions().has(SP.PermissionKind.editListItems));
console.log("view details: " + listToCheck.view.get_htmlSchemaXml());
}
}), Function.createDelegate(this, function()
{
alert("error");
}));
}, "sp.js");
- if all the lists and views exist then the code works
- but if any list or view doesn't exist then the entire thing errors
I'd also like to get field details, particularly the field type, but I can't figure out how to add that to here.