I have some wiki pages in SharePoint 2013 Onpremise "Site Pages" Library. I have created a column "Priority" in the library . I want to access the Page Property from Client Side. I know this is possible from Server side by the following code:
SPContext.Current.ListItem["FieldName"]
But i want to access the Page properties from Client Side , is it possible ?
Since SPContext.Current gets the context of the current HTTP request and SPContext.Current.ListItem
returns the current List Item I assume you to need a similar functionality in JSOM.
In SharePoint the structure _spPageContextInfo
is available on every page on the client-side that could be considered to some extent as analogue to SPContext.Current. In particular, the following properties are exposed to identify the current List Item:
pageListId
- gets the current List Unique IdpageItemId
- gets the current List Item IdThe following function demonstrates how to retrieve current List Item:
function getCurrentListItem(success, error)
{
var context = SP.ClientContext.get_current();
var web = context.get_web();
var currentList = web.get_lists().getById(_spPageContextInfo.pageListId);
var currentListItem = currentList.getItemById(_spPageContextInfo.pageItemId);
context.load(currentListItem);
context.executeQueryAsync(
function(){
success(currentListItem);
},
error
);
}
Usage
getCurrentListItem(
function(listItem) {
var priority = listItem.get_item('Priority');
console.log(priority);
},
function(sender,args){
console.log(args.get_message());
}
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With