Javascript csom to access page properties

I have some wiki pages in SharePoint 2013 Onpremise Site Pages Pages. I created a Priority column in the library. I want to access the Page Property from Client Side. I know that this is possible on the server side using the following code:

SPContext.Current.ListItem["FieldName"] 

But I want to access the properties of the page from the client side, is this possible?

+5
source share
1 answer

Since SPContext.Current gets the context of the current HTTP request and SPContext.Current.ListItem returns the current list item, I assume you need similar functionality in JSOM.

In SharePoint, the _spPageContextInfo structure is available on every page on the client side, which to some extent can be considered an analogue of SPContext.Current . In particular, the following properties are displayed to determine the current list item:

  • pageListId - Gets the identifier of the current List
  • pageItemId - Gets the current list item id

How to get the current list item using JSOM

The following function demonstrates how to extract the 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 ); } 

Using

 getCurrentListItem( function(listItem) { var priority = listItem.get_item('Priority'); console.log(priority); }, function(sender,args){ console.log(args.get_message()); } ); 
+8
source

Source: https://habr.com/ru/post/1201514/


All Articles