Reputation: 133
I am trying to mimic the Alert Me functionality as the business only wants Alert Me and Send a link. In Alert Me I am trying to get the current list's Name and Title when my javascript code is in the allitems.aspx page of my document library. All of the examples I can find assume you know the title of the list already.
Upvotes: 0
Views: 2939
Reputation: 59328
At least the following options could be used to determine list properties (like Title
) in List View page (AllItems.aspx
)
SP.ListOperation.Selection
namespaceSP.ListOperation.Selection.getSelectedList() Method gets the ID of the list being selected:
var listId = SP.ListOperation.Selection.getSelectedList();
The following example demonstrates how to retrieve list by its Id via CSOM (JavaScript):
(function(){
var listId = SP.ListOperation.Selection.getSelectedList(); //selected List Id
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getById(listId);
context.load(list);
context.executeQueryAsync(
function() {
//print List properties
console.log(list.get_title());
},
function(sender,args){
console.log(args.get_message());
}
);
})();
_spPageContextInfo
structure_spPageContextInfo
object is rendered in every SharePoint page and contains property _spPageContextInfo.pageListId
that stores the current List Id:
var listId = _spPageContextInfo.pageListId;
Upvotes: 1