|
| 1 | +--- |
| 2 | +description: 'Complete PCF API reference with all interfaces and their availability in model-driven and canvas apps' |
| 3 | +applyTo: '**/*.{ts,tsx,js}' |
| 4 | +--- |
| 5 | + |
| 6 | +# Power Apps Component Framework API Reference |
| 7 | + |
| 8 | +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. |
| 9 | + |
| 10 | +## API Availability |
| 11 | + |
| 12 | +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. |
| 13 | + |
| 14 | +| API | Model-driven apps | Canvas apps | |
| 15 | +|-----|------------------|-------------| |
| 16 | +| AttributeMetadata | Yes | No | |
| 17 | +| Client | Yes | Yes | |
| 18 | +| Column | Yes | Yes | |
| 19 | +| ConditionExpression | Yes | Yes | |
| 20 | +| Context | Yes | Yes | |
| 21 | +| DataSet | Yes | Yes | |
| 22 | +| Device | Yes | Yes | |
| 23 | +| Entity | Yes | Yes | |
| 24 | +| Events | Yes | Yes | |
| 25 | +| Factory | Yes | Yes | |
| 26 | +| Filtering | Yes | Yes | |
| 27 | +| Formatting | Yes | Yes | |
| 28 | +| ImageObject | Yes | Yes | |
| 29 | +| Linking | Yes | Yes | |
| 30 | +| Mode | Yes | Yes | |
| 31 | +| Navigation | Yes | Yes | |
| 32 | +| NumberFormattingInfo | Yes | Yes | |
| 33 | +| Paging | Yes | Yes | |
| 34 | +| Popup | Yes | Yes | |
| 35 | +| PopupService | Yes | Yes | |
| 36 | +| PropertyHelper | Yes | Yes | |
| 37 | +| Resources | Yes | Yes | |
| 38 | +| SortStatus | Yes | Yes | |
| 39 | +| StandardControl | Yes | Yes | |
| 40 | +| UserSettings | Yes | Yes | |
| 41 | +| Utility | Yes | Yes | |
| 42 | +| WebApi | Yes | Yes | |
| 43 | + |
| 44 | +## Key API Namespaces |
| 45 | + |
| 46 | +### Context APIs |
| 47 | + |
| 48 | +The `Context` object provides access to all framework capabilities and is passed to your component's lifecycle methods. It contains: |
| 49 | + |
| 50 | +- **Client**: Information about the client (form factor, network status) |
| 51 | +- **Device**: Device capabilities (camera, location, microphone) |
| 52 | +- **Factory**: Factory methods for creating framework objects |
| 53 | +- **Formatting**: Number and date formatting |
| 54 | +- **Mode**: Component mode and tracking |
| 55 | +- **Navigation**: Navigation methods |
| 56 | +- **Resources**: Access to resources (images, strings) |
| 57 | +- **UserSettings**: User settings (locale, number format, security roles) |
| 58 | +- **Utils**: Utility methods (getEntityMetadata, hasEntityPrivilege, lookupObjects) |
| 59 | +- **WebApi**: Dataverse Web API methods |
| 60 | + |
| 61 | +### Data APIs |
| 62 | + |
| 63 | +- **DataSet**: Work with tabular data |
| 64 | +- **Column**: Access column metadata and data |
| 65 | +- **Entity**: Access record data |
| 66 | +- **Filtering**: Define data filtering |
| 67 | +- **Linking**: Define relationships |
| 68 | +- **Paging**: Handle data pagination |
| 69 | +- **SortStatus**: Manage sorting |
| 70 | + |
| 71 | +### UI APIs |
| 72 | + |
| 73 | +- **Popup**: Create popup dialogs |
| 74 | +- **PopupService**: Manage popup lifecycle |
| 75 | +- **Mode**: Get component rendering mode |
| 76 | + |
| 77 | +### Metadata APIs |
| 78 | + |
| 79 | +- **AttributeMetadata**: Column metadata (model-driven only) |
| 80 | +- **PropertyHelper**: Property metadata helpers |
| 81 | + |
| 82 | +### Standard Control |
| 83 | + |
| 84 | +- **StandardControl**: Base interface for all code components with lifecycle methods: |
| 85 | + - `init()`: Initialize component |
| 86 | + - `updateView()`: Update component UI |
| 87 | + - `destroy()`: Cleanup resources |
| 88 | + - `getOutputs()`: Return output values |
| 89 | + |
| 90 | +## Usage Guidelines |
| 91 | + |
| 92 | +### Model-Driven vs Canvas Apps |
| 93 | + |
| 94 | +Some APIs are only available in model-driven apps due to platform differences: |
| 95 | + |
| 96 | +- **AttributeMetadata**: Model-driven only - provides detailed column metadata |
| 97 | +- Most other APIs are available in both platforms |
| 98 | + |
| 99 | +### API Version Compatibility |
| 100 | + |
| 101 | +- Always check the API availability for your target platform (model-driven or canvas) |
| 102 | +- Some APIs may have different behaviors across platforms |
| 103 | +- Test components in the target environment to ensure compatibility |
| 104 | + |
| 105 | +### Common Patterns |
| 106 | + |
| 107 | +1. **Accessing Context APIs** |
| 108 | + ```typescript |
| 109 | + // In init or updateView |
| 110 | + const userLocale = context.userSettings.locale; |
| 111 | + const isOffline = context.client.isOffline(); |
| 112 | + ``` |
| 113 | + |
| 114 | +2. **Working with DataSet** |
| 115 | + ```typescript |
| 116 | + // Access dataset records |
| 117 | + const records = context.parameters.dataset.records; |
| 118 | + |
| 119 | + // Get sorted columns |
| 120 | + const sortedColumns = context.parameters.dataset.sorting; |
| 121 | + ``` |
| 122 | + |
| 123 | +3. **Using WebApi** |
| 124 | + ```typescript |
| 125 | + // Retrieve records |
| 126 | + context.webAPI.retrieveMultipleRecords("account", "?$select=name"); |
| 127 | + |
| 128 | + // Create record |
| 129 | + context.webAPI.createRecord("contact", data); |
| 130 | + ``` |
| 131 | + |
| 132 | +4. **Device Capabilities** |
| 133 | + ```typescript |
| 134 | + // Capture image |
| 135 | + context.device.captureImage(); |
| 136 | + |
| 137 | + // Get current position |
| 138 | + context.device.getCurrentPosition(); |
| 139 | + ``` |
| 140 | + |
| 141 | +5. **Formatting** |
| 142 | + ```typescript |
| 143 | + // Format date |
| 144 | + context.formatting.formatDateLong(date); |
| 145 | + |
| 146 | + // Format number |
| 147 | + context.formatting.formatDecimal(value); |
| 148 | + ``` |
| 149 | + |
| 150 | +## Best Practices |
| 151 | + |
| 152 | +1. **Type Safety**: Use TypeScript for type checking and IntelliSense |
| 153 | +2. **Null Checks**: Always check for null/undefined before accessing API objects |
| 154 | +3. **Error Handling**: Wrap API calls in try-catch blocks |
| 155 | +4. **Platform Detection**: Check `context.client.getFormFactor()` to adapt behavior |
| 156 | +5. **API Availability**: Verify API availability for your target platform before use |
| 157 | +6. **Performance**: Cache API results when appropriate to avoid repeated calls |
| 158 | + |
| 159 | +## Additional Resources |
| 160 | + |
| 161 | +- For detailed documentation on each API, refer to the [Power Apps component framework API reference](https://learn.microsoft.com/power-apps/developer/component-framework/reference/) |
| 162 | +- Sample code for each API is available in the [PowerApps-Samples repository](https://github.com/microsoft/PowerApps-Samples/tree/master/component-framework) |
0 commit comments