To retrieve data from specific columns in a SharePoint list after successfully connecting to the list and counting records, you can use either REST API or Microsoft Graph API depending on your setup. Below is an example using JavaScript with the Fetch API for retrieving column values.
Example Using REST API
Assuming you’re working within a context that allows access (like SPFx), here’s how you might fetch data:
const
Explanation:
- Replace
yourtenant
and yoursite
with your actual tenant name and site URL.
- Adjust
$select=
parameter based on which columns you’d like to retrieve (Val A
, etc.).
This code will log out values of “Column A” and "Column B."
If you’re looking specifically for unique entries or filtering by certain criteria (e.g., only where “Value” equals Val A), consider adding query options such as $filter
.
For instance:
.../items?$select=Title,Field1&$filter=Field1 eq 'Val A'
Make sure you’ve set up proper permissions in Azure AD app registration settings when accessing via APIs.
Feel free to adjust this template according to your programming environment!
Certainly! In order to retrieve data from specific columns in a SharePoint list, you can use the REST API or Microsoft Graph API. The example provided uses JavaScript with the Fetch API and demonstrates how to fetch column values using the REST API.
Here’s an explanation of each step:
- Define variables:
-
siteUrl
: Replace this with your SharePoint site URL.
-
listName
: Specify the name of your SharePoint list.
- Create an asynchronous function called
getColumnData
that will handle retrieving column data from the specified list.
- Use the Fetch API to make a GET request to retrieve items (records) from your SharePoint list:
- Constructing the endpoint URL by combining
${siteUrl}/_api/web/lists/getbytitle('${listName}')/items?$select=ColumnA, ColumnB
. This specifies which columns (ColumnA
, ColumnB
) should be included in response results.
- Set necessary headers for authentication and specify
'Accept': 'application/json; odata=verbose'
.
- Check if there was any error during fetching items using
.ok
property on response object.
6a.If no errors occurred, parse JSON response into variable named jsonResponse using .json()
method on Response object returned by fetch() call.
7a.Process retrieved items stored within jsonResponse.d.results array as per requirement: Iterate through each item inside it via forEach loop, Access desired column values like item.ColumnA and item.ColumnB Perform further processing/logic based on these values
8.Call getColumnData() function at end or wherever appropriate point in code execution flow
Remember that when working with APIs such as REST or Microsoft Graph, proper permissions need to be set up either through Azure AD app registration settings or other means depending upon requirements/authentication mechanism used for accessing those APIs.
Feel free modify this template according to programming environment/language being utilized while ensuring compatibility between versions/APIs supported by respective platforms