Archive
[Experimental Feature] Call Dataverse actions directly in Power Fx
In one of my previous articles, I’ve explained the steps to call the Dataverse Custom API from Canvas App using Power Automate cloud flow.
Recently a new experimental feature Call Dataverse actions directly in Power Fx released using which makers can now directly invoke a Dataverse Custom API within a Power Fx formula.
About the feature:
- Power Apps will support the ability to directly call synchronous Dataverse actions without having to create a Power Automate Flow.
- For apps that need to call many Dataverse actions, this will provide a significant performance boost.
- It’ll be much easier to directly call Dataverse actions from the new Power Fx language element Environment.
- The Environment object allows authors to dot into actions available in the environment.
- Its currently an Experiment feature and can be enabled from Canvas Studio -> Settings -> Upcoming features -> Experimental. Turn on the ‘Enable access to Microsoft Dataverse actions’ toggle.
In this article lets learn how to call the Custom API directly in Power Fx formula without the need of Power Automate flow. But first lets get familiar with our Custom API.
Custom API Details:
- I already have a Custom API by name ‘cat_onboardcustomer‘ (Refer article for steps to create Custom API from scratch).
- ‘cat_onboardcustomer‘ API has a request Parameter by name ‘cat_customername‘ of type ‘String’.
Now that we know our Custom API, lets learn how to call the API in Power Fx by building a simple canvas app.
Steps to call Dataverse actions directly from Power Fx:
- Create a Canvas App.
- Open Settings -> Upcoming features -> Experimental. Turn on the ‘Enable access to Microsoft Dataverse actions’ toggle.
- By enabling, A new Power Fx ‘Environment’ language object will be available under ‘Data sources’.
- From the Canvas App, search for the ‘Environment‘ data source as shown below.
- Double click and add the Environment data source.
- Add a button on to the Canvas App and ‘OnSelect’ event, write the following Power Fx formula.
- In the formula, we are calling cat_onboardcustomer API using ‘Environment’ data source.
- We are also passing cat_customername request parameter in json format.
Environment.cat_onboardcustomer({cat_customername: "Calling API from Power Fx is awesome"})
- That’s all needed. Play the App and click the button and you should see the ‘Account’ created with the name “Calling API from Power Fx is awesome”.
🙂
Power Fx | String Interpolation
If you are familiar with C# language’s string interpolation feature now Power Fx does too.
C# String Interpolation Example:
string name = "Mark";
var date = DateTime.Now;
// String interpolation:
Console.WriteLine($"Hello, {name}! Today is {date.DayOfWeek}, it's {date:HH:mm} now.");
In Power Fx, use string interpolation to embed formulas within a text string.
This is often easier to work with and visualize the output than using the Concatenate function or & operator.
Splicing a long string with the ‘&’ operator or ‘Concatenate’ function:
- Following is an example of splicing a string with ‘&’ operator or ‘Concatenate’ function.
"Hello User : " & User().FullName & " Your Email is : " & User().Email // '&' operator
Concatenate("Hello User : ",User().FullName," ;Your Email is : ",User().Email) // 'Concatenate' function
Using Power Fx String Interpolation:
Above String splicing can be easily done using String Interpolation
- Prefix the text string with a $ and enclose the formula to be embedded with curly braces { }.
- To include a curly brace in the text string, use repeated curly braces: {{ or }}.
- String interpolation can be used anywhere a standard text string can be used
$"Hello User : {User().FullName} Your Email is : {User().Email}"
Few more Examples:
$"2+3 = {2+3}"
// result: 2+3 = 5
$"{{this is inside curly braces}}" // result: {this is inside curly braces}
With( {x:5, y:7},
$"Point ({x},{y}) is {Text( Sqrt( x^2+y^2 ), "#.###" )} from the origin" )
// result: Point (5,7) is 8.602 from the origin
With( {FirstName: "John", MiddleName: "Q.", LastName: "Doe"},
$"{Trim( $"Welcome {FirstName} {MiddleName} {LastName}" )}, we're glad you are here!" )
// result: Welcome John Q. Doe, we're glad you are here!
🙂
Power Apps Ideas (Preview)
In this article lets explore the Power Apps “Ideas” feature, which would be a blessing for all App Makers who write formulas using Power Fx.
As we know Power Fx is a programming language for low code, and makes it possible for hundreds of millions of people with Excel-like skills to add advanced logic to their apps.
What is Power Apps Ideas:
Power Apps Ideas is created to help everyone from the new makers to the seasoned IT pros to ease and speed up the formula authoring experience by using the power of AI models.
A quick example:
- I’ve the following Canvas App with Dataverse as Source. App has a Gallery control displaying ‘Department’ table.
- ‘Department’ table has a Date Time field called ‘Establishment Date’ and displaying values in MM/DD/YYYY HH:MM format.
- So what if I want to display ’27/12/2021′ as ’27 December 2021′. You need to form the syntax by yourself which could be tricky.
- Now lets see, how ‘Ideas’ works here.
- Select the date label from Gallery and select ‘Ideas’.
- Go ahead and type the format you are looking for. I’ve typed my desired format as “27 December 2021 5:30 AM“.
- Now click on ‘Get ideas’ button and you would get the formula for your desired format.
- Go ahead an click ‘Apply’, you get following notification, that formula expression has got updated.
- That’s the power of ‘Ideas’.
- Power Apps Ideas feature currently supports only Gallery and Data table controls for the Items property, and it now supports Microsoft Dataverse, Sharepoint List and Excel as connectors.
Methods to use “Ideas”:
There are two methods to benefit from Power Apps “Ideas” in your app.
Method 1: Transform natural language to Power Fx formulas
Method 2: Transform examples to Power Fx formulas
- This is nothing but the Date format example, I’ve explained in above sections.
- With Power Apps Ideas, you can now simply select that field, then in the ideas pane, enter your desired format, and press enter.
- One or a few formula suggestions will be popped out for you to select from.
🙂