A custom Power Apps Component Framework (PCF) control that provides a high-performance, dropdown-style search interface using the Dataverse searchquery action. It supports multi-entity search, advanced OData filtering, pagination, and sorting.
Add the control to a Custom Page, and add that page to your Model-Driven App.
- Multi-Entity Search: Search across multiple specific tables or perform a global search.
- Automatic Flattening: Handles Power Apps'
JSON()quirk where strings are wrapped in{"Value": "..."}objects. - Smart Fallbacks: If no configuration is provided for an entity, it dynamically picks the first available attribute from the result set.
- HTML Highlighting: Supports
{crmhit}tags to bold matching terms in search results. - Advanced Pagination: Full support for
TopandSkipparameters. - Custom Sorting: Sort by relevance (
@search.score) or specific columns. - Test Mode: Offline development support using mock JSON data.
| Property | Type | Usage | Optional | Description |
|---|---|---|---|---|
| EntitiesConfiguration | Multiple | Input | True | JSON defining entities, selectColumns, searchColumns, and filter. |
| OrderBy | Multiple | Input | True | JSON array for sorting (e.g., ["createdon desc"]). |
| Top | Whole.None | Input | True | Number of records to return (Default: 50). |
| Skip | Whole.None | Input | True | Number of records to bypass for pagination. |
| isInTestMode | TwoOptions | Input | True | Toggle to use mock data instead of live API calls. |
| RecordJsonInTest | Multiple | Input | True | The JSON array of mock records to display when in Test Mode. |
| SelectedRecord | Multiple | Output | True | The JSON representation of the picked record. |
In your Canvas App, set the EntitiesConfiguration property. The PCF flattens this automatically:
JSON(
Table(
{
name: "contact",
selectColumns: ["fullname", "emailaddress1"],
searchColumns: ["fullname", "telephone1"],
filter: "statecode eq 0"
},
{
name: "account",
selectColumns: ["name", "address1_city"]
}
)
)
When isInTestMode is true, provide an array to RecordJsonInTest:
JSON(
[
{
'id': "123",
'entityType': "account",
'title': "Mock Account",
'subtitle': "test@test.com"
},
{
'id': "321",
'entityType': "contact",
'title': "Mock Contact",
'subtitle': "test12@test.com"
},
{
'id': "457",
'entityType': "task",
'title': "Mock Task",
'subtitle': "test32@test.com"
}
]
)
The OrderBy property is critical for controlling result relevance and sorting. Due to how the Dataverse Search API and Power Apps interact, specific formatting is required.
Dataverse expects orderby to be a string representing a JSON array. Power Apps Tables, when converted via JSON(), wrap items in a {"Value": "..."} structure. This PCF automatically flattens that structure.
// Set this to the OrderBy property of the PCF
JSON(["createdon"])
The SelectedRecord property is a Bound property that acts as both an Output (sending data to Power Apps) and an Input (pre-populating the control).
// Set this to the SelectedRecord property of the PCF for pre-populating
JSON(
{
'id': "123",
'entityType': "account",
'title': "Mock Account",
'subtitle': "test@test.com"
}
)
The control is engineered to bridge the gap between Power Apps data structures and the strict requirements of the Dataverse Search API:
- API Action: Utilizes the native Dataverse
searchqueryWeb API action, enabling high-performance, cross-entity searching within the environment. - Flattening Logic: The control includes a built-in "sanitizer" that automatically transforms Power Apps' nested
{"Value": "..."}table structures into the flat string arrays (e.g.,["column1", "column2"]) required by the Dataverse OData engine. - Highlighting: Full support for
{crmhit}and{\/crmhit}tags. These are dynamically converted to styled HTML<b>tags to provide immediate visual feedback for search matches in the results list. - Type Safety: Prevents the common "Stream not readable" deserialization error by ensuring all parameters match the expected OData types:
TopandSkip: Explicitly cast toEdm.Int32(Numbers).EntitiesandOrderBy: Stringified into valid JSON to matchEdm.Stringrequirements.
- Case Sensitivity Handling: Automatically converts attribute keys to lowercase during the mapping process to ensure they align with the logical name keys returned in the Dataverse
Attributescollection. - Robust Error Handling: Uses
String()casting on result titles to prevent the control from breaking if a primary field contains a Numeric or Null value instead of a String.
