2013, 2016, Development Blog, Office 365, SharePoint
This article aims to help you access the data AFTER you’ve successfully loaded the list data.
Keep in mind
There is no exhaustive list of properties for list items, due to:
- Custom columns (that you or your organisation may have added to the list you are accessing)
- Custom content types (I RARELY have the luxury of dealing with anything out-of-box – most of the time, content types are customised for individual organisation needs).
This is why you need to know your data, and if you have problems finding properties, you can use the method below to help you focus in on the ones you need to access.
Let’s get started
Set your breakpoint inside your list item enumerator – either with a debugger; statement or by selecting the line number.
When you refresh your browser window, the breakpoint should be hit and will allow you to test some things out in your Watch pane.
When the breakpoint is hit inside your list enumerator, add the following to your Watch pane (by clicking the plus sign in the top-right):
This should yield the following in your Watch pane:
You can access these properties via
so some examples would be:
listItem.get_item("ID").toString(); // This is an INT, which we can convert to a string or leave as an INT. listItem.get_item("Author").get_lookupValue(); // This is a lookup field, so if you want the value, you use .get_lookupValue(); listItem.get_item("Title"); // This is plain text, so you can access the property directly listItem.get_item("Modified"); // This is a DateTime field, which you can format like the example below: listItem.get_item("Modified").format('dd MMMM yyyy'); // Outputs: 10 August 2016
Your Watch pane may look something like this with some of the values above:
You can also browse their properties by expanding the items with arrows.
Comments are closed