Canvas Apps are a powerful way to build business applications with minimal coding, using Power Fx as the underlying formula language to drive logic and data interactions. To further enhance the flexibility and maintainability of apps, Power Fx has introduced two key features: User Defined Types (UDTs) and User Defined Functions (UDFs). These additions empower developers to build more maintainable and efficient applications by improving formula reuse and data structure management.
Understanding User Defined Functions (UDFs)
User Defined Functions allow developers to encapsulate logic within reusable formulas in Canvas Apps. Previously, Power Fx functions were strictly declarative, meaning they couldn’t perform actions such as modifying variables or triggering notifications. The new update introduces behavior functions that can now include actions such as:
- Set – Assign values to variables.
- Collect – Add or update records in collections.
- Reset – Restore controls to their initial values.
- Notify – Display messages for users.
Actually understanding the concept
Think of building a Canvas App like running a restaurant. Before User Defined Functions (UDFs) and User Defined Types (UDTs), every dish had to be prepared from scratch each time it was ordered—every ingredient measured, every step repeated manually. This often led to inefficiencies, inconsistencies, and wasted effort.
Now, with UDFs, it’s like having a well-organized recipe book in the kitchen. Instead of repeating the same steps for each order, you can simply follow a predefined recipe, ensuring consistency and saving time. Need to adjust how a dish is prepared? Update the recipe once, and it applies everywhere. On the other hand, UDTs are like having pre-portioned ingredient kits—no more guessing quantities or worrying about missing items. You get structured, reliable ingredients every time, making it easier to whip up dishes accurately and efficiently.
With these new features, your app development process becomes smoother, faster, and more reliable—just like a well-run restaurant kitchen.
When Should You Use UDFs?
Consider using UDFs when you need to:
- Modularize complex logic to improve app structure.
- Avoid repetitive formulas by centralizing operations.
- Simplify maintenance by ensuring consistency across your app.
Example of a Behavior UDF:
CountUp(increment: Number) : Void = {
Set(x, x + increment);
Notify($"Count: {x}");
};
In this example, the function CountUp increases a variable and displays a notification. It can be triggered from controls such as buttons to perform actions with side effects.
Understanding User Defined Types (UDTs)
User Defined Types introduce structured data types into Power Fx, allowing developers to work with complex records and tables instead of being limited to simple data types like numbers and text.
Benefits of UDTs
- Stronger data integrity – Define clear structures to prevent errors.
- Improved maintainability – Centralize data definitions for easier updates.
- Seamless API integration – Convert JSON data into strongly typed objects for better usability.
Example of Defining a UDT:
PaperType := Type( { Name: Text, Width: Number, Height: Number } );
PaperArea(Paper: PaperType): Number = Paper.Width * Paper.Height;
Here, PaperType defines a structured format that includes text and numeric fields, which can then be used within functions.
Using UDTs with JSON Data
UDTs simplify the handling of JSON data retrieved from web APIs. Instead of dealing with loosely structured objects, UDTs allow developers to define and manipulate typed data structures with ease.
MoreTyped = ParseJSON(MorePaperSizes, MultiPaperType);
AddColumns(MoreTyped, InStock, true); // OK
By defining data types explicitly, operations such as filtering and sorting become more efficient and error-free.
How Do These Features Differ from Existing Options?
When Should You Use These Features?
- Leverage UDFs to encapsulate logic that needs to be reused across different controls.
- Utilize UDTs when working with structured data such as API responses or complex configurations.
How to Get Started
To experiment with UDFs and UDTs, enable the experimental features in your Canvas App settings:
- Navigate to Settings > Updates > Experimental
- Activate Behavior UDFs and User Defined Types
These features are currently in an experimental phase, so your feedback will be valuable in refining them before general availability.
By adopting UDFs and UDTs, Power Fx developers can achieve better reusability, maintainability, and efficiency in their applications. Now is a great opportunity to explore these capabilities and enhance your app development process.


Leave a Reply