How to do error handling in Power Automate?

When a connector fails, Power Automate’s default response is to exit the workflow immediately and report the entire run as a failure. Most of the time, this is what you want, but there are times when you need to treat a mistake on your own and take custom steps, such as ignoring it or applying a retry pattern. In this tutorial, I will walk through how we can do error handling in Power Automate.

Duplicate detection in Canvas based PowerApps

This video covers information on how to create Canvas Based PowerApps with Duplicate detection. After duplicate detection, you can either Update the existing record, ignore and save or cancel the record creation. #PowerApps #DuplicateDetection #PowerApps

Why and how to use Service principal to trigger PowerAutomate?

Have you faced trouble when you use “When a record is created, updated or deleted trigger”? In my case, it took a long time to trigger or sometimes doesn’t trigger at all. It worked for Depreciated Dynamics connector but with the CDS connector, it seems to be an issue.

I switched to using Service Principal for connecting with the PowerAutomate and it greatly solved this issue while I couldn’t find any official documentation which mentions this solution though.

What is Service Principal?

PowerAutomate or any automation tool required privileges to access data. In order to access data, we use connections in PowerAutomate. And usually, with PowerAutomate, it’s more convenient to use a user account to set up a required connection but it comes with its own baggage. With service Principal, you create an application within Azure Active Directory, which is authorized to access resources or resource groups in Azure and the assign security roles to that user.

Why service principal?

  • Removes dependency from a user account.
  • Provides better security and keep the access limited to the application rather than a use.
  • Make it configurable for the minimal permissions required by the flow and ensures the flow actions are not tied to a specific human user.

How to connect to service principal?

When creating a PowerAutomate, you can click on Connect with Service Principal.

You need to provide Client ID and Client Secret along with Tenant Id to establish a connection. You can check below to see how you can do that.

How to create service principal?

For creating a service principal, you need to register an app in Azure and give the access to that app to access data for user impersonation.

  • Go to portal.azure.com
  • Search for Azure Active Directory or click from the Azure Services list.
  • Go to App registration to register an app.
  • Register an application. Give a suitable name and Select a supported account type, which determines who can use the application. Under Redirect URI, select Web for the type of application you want to create. Enter the URI where the access token is sent to.
  • You can get the Client ID and Tenant ID from the overview screen.
  • For client secret, click + New client secret and generate a secret. Copy the secret and put it into your PowerAutomate connection and select user impersonation.
  • You need to provide API permission to access Dynamics 365 Data. Go to + Add a permission, Click on Dynamics CRM.

Creating a application user to impersonate.

  • Go to Advanced Settings
  • Click on Settings > Security > Users.
  • From the view selector, select Application user.
  • Click + New
  • Select Application user from the form selector.
  • Paste the Application ID of the registered App on the Application ID field.
  • And give the appropriate security role to this user.
  • And voila you’re done.

CSS in PowerApps

Cascade Style Sheet or CSS in PowerApps is a capability that I wish will be part of a core feature of PowerPlatform someday. CSS has gone far past mere aesthetics to create unparalleled versatility. CSS is not only used, contrary to common opinion, to provide a web page with a simple style to make it appear more appealing. There are lots of other things that one can also do with CSS. 

With PowerApps, we wish there is a direct method to apply CSS to the App that we are building. Anyone who knows WordPress can feel that a simple additional CSS feature that comes with it empowers us to optimize every visual element on your site.

While Actual CSS is not possible, there are few things that we can do. 

  1. Create a pseudo CSS by creating an object and defining styling values.
  2. using inline CSS in HTMLText  

Create a pseudo CSS by creating an object and defining styling values

In this example, we will learn how to create pseudo CSS for button control in the PowerApp.

  • Go to App in the Tree View and select OnStart Property.
  • Create a style object on the OnStart Property.
CSS in powerapps
Set(ButtonCSS, {
FontFamily: Font.'Segoe UI',
BackgroundColor: RGBA(127, 178, 57, 1),
BorderThickness: 1,
Color: RGBA(255,255,255,1),
Padding: 8,
TextAlign: Align.Center
})

Now create a button and set values of ButtonCSS in the property of the button.

CSS in powerapps

Using inline CSS in HTMLText  

An HTML text control is a control in PowerApps that shows plain text and numbers and converts HTML tags, such as non-breaking spaces. Sadly, we can’t define global CSS in the HTML text control, but the best thing that we can do is define inline CSS.

CSS in powerapps

As a workaround for setting global CSS, you could set global variables in the OnStart method.

Set(myStyle, “color:blue;font-size:46px;”)

Then in the HTML text control…

"<p style='"&myStyle&"'>
      I'm a big, blue, <strong>strong</strong> paragraph
    </p>"
CSS in powerapps

And that’s it. This is how you can somehow implement the CSS like an attribute in PowerApps. We expect more to come on the platform itself in the future, but I hope it works out as a workaround for now.

HOW TO: Change Icon Background Color of PowerApps Controls

I was working on one of my PowerApps projects where there were some fancy design requirements to be implemented. While working on it, I found that there is a good enough inconsistency in changing the Icon background color of the controls that are available in the PowerApps.

In this article, I am writing about all the different ways you can change Icon Background color of all the controls in the PowerApps.

What is Icon Background color?

On the right side of DatePicker, Dropdown and ComboBox, there is a icon, clicking on which you’ll get calendar, list of items depending on which control it is. The background of that section is pretty easily but inconsistent so can be tricky.

Changing color of Icon Background of controls in PowerApps Controls

Changing Icon Background in different Controls.

  1. Date Picker: You can go to property selector of the DatePicker control and put the color code in the IconBackground property. You don’t have option to change it from the right side property panel.
Changing color of Icon Background of controls in PowerApps Controls

2. DropDown & Combobox: You can change it from the ChevronFill property from the property selector. You can also change it from the right side of the property panel and select the color.

Changing color of Icon Background of controls in PowerApps Controls
Changing Chevron color from property selector.
Changing color of Icon Background of controls in PowerApps Controls
Changing Chevron Color from the property panel.

How I created a Piano in PowerApp

Fews days back, I saw a tweet seeking people interested in creating a tutorial of a Christmas app for kids. I replied over that tweet. With that I connected with Rory of PowerApps4Kids, I pitched him the idea of the piano where we have to play the note of the Jingle Bell correctly. And if you play the whole notes correctly then you have Santa at your windows.

The way, I approached this is. First, there are a couple of objects that you need to place on screen.

  • Image Control:
    • Image of the window in the background
    • Image of Santa
    • Image of Mery Christmas
  • Button Control:
    • The piano keys
    • Reset button
  • Label Control:
    • To show the key to press
  • Audio Control:
    • That plays the keynotes
  • Gallery:
    • To place button controls

You can find all the required media sources at Games/SantaPiano at master · powerapps4kids/Games (github.com)

Place Image of Window in the canvas. Go to Insert>Media>Image. On its Image property set value as “https://raw.githubusercontent.com/powerapps4kids/Games/master/SantaPiano/image.jpg” and set its Image position as Fill

My original idea was to place all the keys at once. Rory gave a clever idea of using a gallery to place all those keys in a gallery so that there is less copy-pasting of codes to each key. Insert a gallery into the canvas name it as galNotes. Go to Insert > Gallery > Horizontal and set its Items as

["C","D","E","F","G","A","B"]
Piano in PowerApps

Inside the gallery, add the button. Change its background fill as white. And set the text property of button as

ThisItem.Value

Add label with fill as Black to show black keys. Though it won’t be functional. You can use button and use the notes for them to make it functional though.

Insert a audio media set its Media property as

"https://raw.githubusercontent.com/powerapps4kids/Games/master/SantaPiano/"&galNotes.Selected.Notes&".mp3"

Now, on the Start property of the Audio control, we set its value as gvStartAudio

Piano in PowerApps

Select the button on the gallery and change its onSelect Property as

Set(gvStartAudio, false); Set(gvStartAudio,true)

We are setting it to false and back to true. This changes the value of gvStartAudio, making the Audio trigger since it has gvStartAudio on its start. If you have it set to true, it will play once and won’t play again.

We create label where show the code to display. On its Text

Last(FirstN(["E","E","E","E","E","E","E","G","C","D","E","F","F","F","F","F","E","E","E","E","E","D","D","E","D","G","E","E","E","E","E","E","E","G","C","D","E","F","F","F","F","F","E","E","E","E","G","G","F","D","C"],isCorrect)).Value

Now, we add an extra function to the piano key to check whether we are pressing the right keys. So, the final code looks like this.

Set(gvStartAudio, false); Set(gvStartAudio,true); If(ThisItem.Value=LabelNote.Text,Set(isCorrect,isCorrect+1)

We need to set an initial value for isCorrect so go to App on the left and on its onStart Property put this function

Set(isCorrect,1)

When we press the right keys the santa would appear, you need an 52 notes to be played correctly. So, Insert the image of Santa and Merry christmas. After that on its Visible property you can put following function.

isCorrect>51

This will show santa where the correct notes are played. And it will appear. In order to make it more interactive, may be you can change the color of highlight keys by changing its fill if thats the right keys. If(Self.Value=LabelNote.Text, Gray, White)

In conclusion, you get a cool Piano Santa Christmas app to play with. The whole course will be available with some other courses at Power Apps 4 Kids – Big Kids and Little Kids . You can also check PowerApps4Kids youtube channel to check Rory teaching you to make this app.