Archive

Posts Tagged ‘Power FX’

[Experimental Feature] Call Dataverse actions directly in Power Fx

March 1, 2023 1 comment

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”.

🙂

Advertisement
Categories: Canvas Apps Tags: ,

Model Driven App | Command Bar | Power Fx formula examples

February 9, 2023 Leave a comment

I’ve written an introductory article on Command Bar when the feature was in preview state. Now that the Command Bar evolved with Power Fx, lets learn few scenarios using Command Bar with Power Fx.

I am taking a scenario of Cloning a record with following design:

  • Add new Command button on Command Bar
  • On ‘OnSelect’, write Power Fx Patch formula to create a new record from existing record.
  • Write a Visibility rule, to display the Command button only on ‘Edit’ form.

Lets get started.

Add a new Command button and implement Clone functionality:

  • Open the Model Driven App in editor and select a table which you would want to place the Clone button. click on ‘Edit command bar’.
  • Selected ‘Main form’ as we are going to add ‘Clone’ button on form.
  • Add a new ‘Command’ button and provide details like Label, Icon, etc…
  • We need to write ‘Power Fx’ formula on ‘OnSelect’ event of the command button.
  • We can write the formula in the formula text box at the top but its not intuitive. One option is to write the formula by clicking on ‘Open component library’, which opens up Canvas app editor.
  • Click on ‘Open component library’.
  • Point to be noted is every time you add a new Command button, it creates a component in the background.
  • Once the ‘Command Library’ window opens up, under ‘Tree View’, you can see a separate component for each command button you have in your MDA.
  • Coming back to our Clone scenario, select the ‘Clone Customer_1’ component and on ‘OnSelect’ event, write the PowerFx formula to clone the current record.
    • I am using Patch function with Defaults(Customers) which creates a new record.
Notify("Cloning the Customer...");

Patch(

    Customers,

    Defaults(Customers),

    {

        Name: "Clone - " & Self.Selected.Item.Name,

        Gender: [@Gender].Male,

        'Date of Birth': Self.Selected.Item.'Date of Birth',

        'Mobile Number': Self.Selected.Item.'Mobile Number'

    }

);

Notify("Cloning completed successfully !!!");
  • Click on ‘Publish’ icon and close the window.
  • Come back to the MDA editor and you would see the clone Power Fx formula prepared in Components library screen.
  • Click on ‘Play’ to test the ‘Clone Customer’ button in your MDA.
  • Open a Customer record and click on ‘Clone Customer’ button.
  • Up on successful clone, you would get the ‘Cloning completed successfully’ notification and you can even open the new cloned record.

Command Visibility Formula:
  • Now that we achieved the clone functionality, lets add a validation by showing the ‘Clone Customer’ command only on Edit form.
  • Go back to MDA editor and select the ‘Clone Customer’ command and set Visibility as ‘Show on condition from formula’.
  • In the formula, specify formula as
Self.Selected.State = FormMode.Edit
  • Publish and Play the App and you would see the ‘Clone Customer’ button only on edit form but not on create form.

🙂

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)

February 3, 2022 Leave a comment

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.

🙂

Categories: PowerApps Tags: , ,

[Preview Feature] Model Driven Apps | Edit Command Bar

August 15, 2021 1 comment

In this article lets explore the ‘Edit Command Bar’ preview feature available in Model Driven Apps designer. But first lets understand the following basics of Command Bar.

  • What are Command Bars?
  • Where do we find them in Model Driven App (i.e., Command bar locations)?

What are Command Bars?

  • Command bars are at the core of every model-driven app and appear in many different locations.
  • The group of commands associated with a specific location make up a command bar.

Command bar locations in Model Driven App:

  • Main grid. This command bar is displayed when using the left-hand navigation of an app to view a full page list of records in this table.
  • Main form. This command bar is displayed on the table’s main forms. This appears at the top of the form and is not the same as the associated view or subgrid view that will appear in different areas of the form.
  • Subgrid view. This command bar is displayed on forms of other tables that render this table’s data within a subgrid.
  • Associated view. This command bar is displayed on the form of a parent table when viewing related data in this table.
  • Quick actions. There isn’t a specialized entry point from the command designer because quick actions are edited from the main grid of the table.

Now that we got the basics, lets explore editing the Command bar.

Using ‘Edit command bar (preview)’:

  • To use ‘Edit command bar (preview)’ feature. Connect to Power Apps portal.
  • Create a new ‘Model-driven app from blank’ and select the ‘Modern app designer (preview)’.
  • Add a Page and link one of your Dataverse Table.
    • I’ve added ‘Student’ table as Page.
  • Now click on ‘…’ of ‘Student’ and click on ‘Edit command bar (preview)’.
  • From the options choose one of the ‘Command Bar’ location you would like to edit.
  • In the next screen, you will get all the available of Commands displayed as below.
    • At this point editing ‘Legacy button is not supported’. Refer the limitations here.
  • I am going to add a new ‘Command’ named ‘Open My Blog’ which opens up an URL.
  • Click on ‘+New command’ and provide details on the right pane.
  • Action property specifies what happens on the ‘Select’ of the ‘Command’. Below are 2 available options.
  • As I need to open URL on the select of my ‘Open My Blog’ command. Under Action’ choose ‘Run formula’ and in the formula bar add ‘Launch()’ Power Fx as below.
  • Click ‘Save and Publish’ and ‘Play’.
  • On your App, you should see the command and on select it redirects to the provided URL.

Refer the docs link for more details.

🙂

Categories: PowerApps Tags: ,