Skip to content

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.

License

Notifications You must be signed in to change notification settings

SahilATech/DataverseSearch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dataverse Search PCF Control

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.

🚀 Features

  • 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 Top and Skip parameters.
  • Custom Sorting: Sort by relevance (@search.score) or specific columns.
  • Test Mode: Offline development support using mock JSON data.

⚙️ Property Configuration

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.

1. Defining Search Entities

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"]
        }
    )
)

2. Mock Data for Test Mode

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"
        }
    ]
)

3. OrderBy Configuration

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"])

4. SelectedRecord Property

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"
    }
)

📝 Technical Implementation Details

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 searchquery Web 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:
    • Top and Skip: Explicitly cast to Edm.Int32 (Numbers).
    • Entities and OrderBy: Stringified into valid JSON to match Edm.String requirements.
  • 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 Attributes collection.
  • 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.

RangeBoundDatePicker


Solutions

Managed Solution

Unmanaged Solution

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published