Power Apps Component Framework API Reference

Coding standards for pcf api reference.instructions

typescript
express
0 downloads
0 views
0

Power Apps Component Framework API Reference

The Power Apps component framework provides a rich set of APIs that enable you to create powerful code components. This reference lists all available interfaces and their availability across different app types.

API Availability

The following table shows all API interfaces available in the Power Apps component framework, along with their availability in model-driven apps and canvas apps.

APIModel-driven appsCanvas apps
AttributeMetadataYesNo
ClientYesYes
ColumnYesYes
ConditionExpressionYesYes
ContextYesYes
DataSetYesYes
DeviceYesYes
EntityYesYes
EventsYesYes
FactoryYesYes
FilteringYesYes
FormattingYesYes
ImageObjectYesYes
LinkingYesYes
ModeYesYes
NavigationYesYes
NumberFormattingInfoYesYes
PagingYesYes
PopupYesYes
PopupServiceYesYes
PropertyHelperYesYes
ResourcesYesYes
SortStatusYesYes
StandardControlYesYes
UserSettingsYesYes
UtilityYesYes
WebApiYesYes

Key API Namespaces

Context APIs

The Context object provides access to all framework capabilities and is passed to your component's lifecycle methods. It contains:

  • Client: Information about the client (form factor, network status)
  • Device: Device capabilities (camera, location, microphone)
  • Factory: Factory methods for creating framework objects
  • Formatting: Number and date formatting
  • Mode: Component mode and tracking
  • Navigation: Navigation methods
  • Resources: Access to resources (images, strings)
  • UserSettings: User settings (locale, number format, security roles)
  • Utils: Utility methods (getEntityMetadata, hasEntityPrivilege, lookupObjects)
  • WebApi: Dataverse Web API methods

Data APIs

  • DataSet: Work with tabular data
  • Column: Access column metadata and data
  • Entity: Access record data
  • Filtering: Define data filtering
  • Linking: Define relationships
  • Paging: Handle data pagination
  • SortStatus: Manage sorting

UI APIs

  • Popup: Create popup dialogs
  • PopupService: Manage popup lifecycle
  • Mode: Get component rendering mode

Metadata APIs

  • AttributeMetadata: Column metadata (model-driven only)
  • PropertyHelper: Property metadata helpers

Standard Control

  • StandardControl: Base interface for all code components with lifecycle methods:
    • init(): Initialize component
    • updateView(): Update component UI
    • destroy(): Cleanup resources
    • getOutputs(): Return output values

Usage Guidelines

Model-Driven vs Canvas Apps

Some APIs are only available in model-driven apps due to platform differences:

  • AttributeMetadata: Model-driven only - provides detailed column metadata
  • Most other APIs are available in both platforms

API Version Compatibility

  • Always check the API availability for your target platform (model-driven or canvas)
  • Some APIs may have different behaviors across platforms
  • Test components in the target environment to ensure compatibility

Common Patterns

  1. Accessing Context APIs

    typescript
    // In init or updateView
    const userLocale = context.userSettings.locale;
    const isOffline = context.client.isOffline();
  2. Working with DataSet

    typescript
    // Access dataset records
    const records = context.parameters.dataset.records;
    
    // Get sorted columns
    const sortedColumns = context.parameters.dataset.sorting;
  3. Using WebApi

    typescript
    // Retrieve records
    context.webAPI.retrieveMultipleRecords("account", "?$select=name");
    
    // Create record
    context.webAPI.createRecord("contact", data);
  4. Device Capabilities

    typescript
    // Capture image
    context.device.captureImage();
    
    // Get current position
    context.device.getCurrentPosition();
  5. Formatting

    typescript
    // Format date
    context.formatting.formatDateLong(date);
    
    // Format number
    context.formatting.formatDecimal(value);

Best Practices

  1. Type Safety: Use TypeScript for type checking and IntelliSense
  2. Null Checks: Always check for null/undefined before accessing API objects
  3. Error Handling: Wrap API calls in try-catch blocks
  4. Platform Detection: Check context.client.getFormFactor() to adapt behavior
  5. API Availability: Verify API availability for your target platform before use
  6. Performance: Cache API results when appropriate to avoid repeated calls

Additional Resources

Tags

testing
security
performance
best-practices
documentation
error-handling
api