Power Apps Code App Series
This article is Part 2 of our Power Apps Code App series:
Part 2: Retrieving Dataverse records
In this section, we demonstrate how to retrieve Dataverse records using a Power Apps code app. This implementation follows the official guidance but uses custom application code to fetch and render Contact data in a React-based environment.
Missed Part 1? Read our guide on creating a Power Apps Code App from scratch here.
This approach gives developers fine-grained control over query options, error handling, and UI rendering while still leveraging Microsoft Power Platform services.
The goal of this example is to:
Retrieve the latest 10 Contact records from Dataverse.
Select only required fields for performance optimization.
Display the data in a clean, user-friendly UI.
Handle loading and error states gracefully.
Adding Dataverse as a Data Source to the Code App
Before a Power Apps code app can interact with Microsoft Dataverse, it must be explicitly registered as a data source. This is done using the Power Platform CLI.
Enterprise deployments often require secure data modeling, compliance controls, and system integration planning.
This step is mandatory because it enables:
Service generation for Dataverse tables.
Strongly typed APIs (such as ContactsService).
Secure, environment-aware data access.
1. Register the Contact Table
From the root of your code app project, run the following command to register the table. This generates the strongly typed services under /generated/services/ContactsService.
Using the Generated Contacts Service
When a code app is initialized and Dataverse services are generated, Power Apps creates strongly typed service classes. In this example, the app uses a generated ContactsService to retrieve Dataverse records instead of manually calling the Web API.
Note: Without the registration step above, ContactsService will not exist, and your app will fail at compile time.
2. Import the Service
Defining Query Options and Retrieving Data
To retrieve Dataverse records efficiently, query options are defined using a local interface that mirrors Dataverse query capabilities such as $select, $orderby, and $top.
3. Define Query Options
Key considerations:
Select only required columns to reduce payload size.
Order records by createdon to get the most recent contacts.
Limit results using top to improve performance.
4. Call the getAll Method
The actual data retrieval is performed using the getAll method provided by the generated service:
The complete implementation for this example is available in our Git repository. Refer to App.tsx for the Dataverse data retrieval logic and App.css for the UI styling. Additional files can be referenced if deeper implementation details are required.
If data is returned successfully, the records are stored in React state and rendered in the UI. Any exceptions are captured and displayed to the user.
Rendering Contacts in the UI
Once retrieved, the Contact records are displayed in a structured layout showing:
- Full name
- Job title
- Phone number
- Email address
This demonstrates how Dataverse data can be seamlessly bound to UI components in a code-first Power Apps experience.
Need Secure Dataverse and Backend Integration?
- Dataverse data modeling
- Enterprise API integration
- Performance optimization
- Governance and compliance support
FAQs
How do I add Dataverse as a data source in a code app?
You must use the Power Platform CLI command: pac code add-data-source -a dataverse -t <table-name>. This registers the table and generates the necessary TypeScript service files for strongly typed access.
What is the benefit of using the generated ContactsService?
The generated service abstracts away complex tasks like authentication, endpoint management, and response parsing. It allows you to retrieve Dataverse records using simple method calls (like getAll) rather than manually constructing Web API HTTP requests.
Can I filter the records retrieved from Dataverse?
Yes. The service accepts an options object where you can define standard OData query parameters, including select (to limit columns), orderBy (to sort data), filter (for specific criteria), and top (to limit the number of records).
Why should I select only specific columns?
Selecting only the columns you need (using the select array) significantly reduces the payload size sent over the network. This improves the performance and load time of your Power Apps code app, especially on mobile devices.
How do I optimize Dataverse queries for large datasets?
Limit selected columns, use indexed fields, apply server-side filtering, and implement pagination to improve performance.
How does Dataverse support enterprise security?
Dataverse includes role-based access control, field-level security, and environment-level governance policies.
Can Dataverse integrate with external enterprise systems?
Yes. Dataverse supports API-based integrations, Azure services, and Power Platform connectors for enterprise integration scenarios.


