Using Power-Fx commands in Vs Code Terminal – Preview

Hi Folks,

Looking to improve your experience developing code using Power Fx. Then try this feature which was in preview…I want to show you how you can execute them. It is actually quite ideal for prototyping, debugging, testing to see the Power-Fx expression behavior. If you were new to Power-Fx, you can check my introductory post here on this which I wrote way back in 2021.

All you can do this is to execute few commands from VS Code, they directly run on your Dataverse environment.

Few prerequisites to follow:

  1. Install VS Code (install from here)
  2. Install Power Platform CLI (install from here)
  3. Install PowerShell Module for VS Code (install from here)
  4. Install Power Platform Tools for VS Code (install from here)
  5. Once you have everything installed you were good to go, few more steps required to set up your VS Code to run successfully.

As you have already installed the Power Platform Tools extension above, you should see an icon at the side bar as highlighted below.

Create an authentication profile for your target environment, click on the plus symbol besides the AUTH PROFILES, I have already created few earlier.

Provide your login credentials using the login prompt.

Once authenticated, you should be able to see all your environments in your tenant like below.

Open a terminal in VS Code

You should see something like below.

Now you were all set to run Power-Fx Commands targeting your envirnment, let’s try it out. In order to interact with Dataverse, use the below commands, thereby reducing the time and complexity of your Dataverse operations by using Power Fx.

1: pac org who: Displays information about your current Dataverse Organization

2: pac admin list :List all environments from your tenant.

3. Read-Eval-Print Loop & Dataverse Commands

We heard about Read-Eval-Print Loop while working on other languages mainly Python, we now have that included while using Power Fx, to start using if. Enter the below in your Vs Code Terminal, it should show something like below and now you can execute commands and once connected, you can use Dataverse commands.

By the way, we need to use Plural names below.

pac power-fx repl command:

a. Add Rows: Use Collect (Contacts, { firstname: “Pavan”, lastname: “Mani Deep”})

b. Help: Use Help ()

c. Exit: Use Exit() to exit the repl command

4. Run Power-Fx Commands from a file: All you need to do is save the Power-Fx commands in a text file at the below location.

pac power-fx run:

With this command, you can run a file of Power Fx instructions.

a. Create Dataverse records: By using same Collect Command we used above in a file.

Now execute the command

pac power-fx run –file Name of the file -e true

b. Query a Dataverse table: Save the below command in a file located in the folder path.

Now execute the command

c. Filter a Dataverse table: While I used the filter command, I was not able to filter the data, rather I was getting null. I hope Microsoft will be fixing this when these features are out of preview.

I hope this gives you an idea of how you can execute Power-Fx commands within your favorite IDE(Vs Code).

Cheers,

PMDY

My top 3 favorite features released at Build 2024 for Canvas Apps…

Hi Folks,

This sounds good for those who are Pro Dev and also those working on Fusion teams (Pro + Low Code), as well. Just note, all these features are in preview or experimental features and are available in US Preview Region now as they were just released in the Microsoft Build 2024 last week. Public preview of these features is expected to be released in June 2024, so you can then try out in your region as well. If you want to check these out now, spin up a trial in US Preview region.

These are the top new features

  1. View the Code behind the Canvas Apps
  2. Use Copilot to generate comments and expressions for your Canvas Apps
  3. Integrate Canvas Apps with GitHub

Feature #1: View the Code behind the Canvas Apps

Now you can view the code behind your Canvas Apps, besides the screen where the components reside, click on the ellipses as below

You should be able to see the YAML source code for your Canvas App, the code is currently read only, you can click on Copy code option in the above screen at the bottom of page.

Make the necessary changes to the YAML code, create a new blank screen and you can then copy the YAML code to recreate the previous screen for which you copied the YAML code into a new screen if you wish you.

Here I will copy the code for the container inside, then I will create a new Blank screen

Once blank screen is added, expand it so that it occupies the entire size of the App, then click on Paste as below

Give it a minute, your new screen is now ready with container inside as below e.g here it was Screen3, just rename this accordingly.

How easy it was…. make sure you copy it to relevant item, meaning if you copied the code of container, you could only copy it to another container and not a screen.

Feature #2: Use Copilot to generate comments and expressions for your Canvas Apps

Do you want to generate comments for the expressions you wrote. Or have you forgot the logic which you have written for Canvas Apps long time back, don’t worry, use this approach.

Let’s say, I am choosing OnSelect Property, I have the below formula

Let’s ask Copilot what this mean, click on the Copilot icon available as below

Choose to explain the formula

So now you click on Copy option available and paste it above your command, this serves as a comment for your expression, you can try for any complex expression you wrote in your App. This improves the readability of your app and also makers can use existing knowledge to quickly get up to speed, minimize errors, and build—fast next time you were working on the same App

Now you can generate Power Fx using Copilot, you can start typing in natural language what you need in comments and as soon you stop typing, it shows as generating as below…you could use either // and /* */, comments can remain in the formula bar as documentation, just like with traditional code.

It generates the Power Fx command for your input as below and then you need to click on Tab key on your keyboard, it will show something like below

And finally, you can see the output as below.

You can apply these two tips for complex formulas as well.

Feature 3: Integrate Canvas Apps with GitHub

Did you ever notice that if the canvas app was opened by one user, when another user tries to open the same Canvas app, you would see a warning message and you need to explicitly click on override to take it forward, meaning at any point of time, only one person could be able to work on the Canvas App.

Now we can use first class Devops with the GitHub Integration feature enabled, many people can work on the same canvas app at the same time and also commit the code for Canvas Apps to Git, let’s see this.

Prerequisites:

  1. You need to have a GitHub Repo created, creating branches is optional, we can use main branch otherwise.
  2. Enable the experimental feature as below

Then you should see

Next thing is you need to configure Git version control as below, you can either use GitHub or Azure DevOps for this, I want to create a new Directory for storing my canvas app like GitHub Test which is not yet in my GitHub Account.

You need to your GitHub Account settings to create a new token as below.

For the personal access token, give repo level scope and click generate token.

Copy the personal access token in the connect to a Git Repository window, once authenticated, you should see a message like below.

Click Yes, you should see something like below

Within a minute, you should the below screen w

So, you should the code files being created in your GitHub Account as below

Now, your team can make the changes in the GitHub, since GitHub allows multiple people to work on it, latest commit will be reflected whenever you try to open the Canvas App from the maker portal. This helps developers build and deploy to source control without leaving the maker portal. Whenever you try to open this app, it will ask your Git Account credentials.

Do note that these features are currently available in US Preview region as they are just released last week in Build and would be released to other regions in near future, possibly in June 2024.

Hope you learned something new coming up next month or sooner…

That’s it for today…

Cheers,

PMDY