Implement character length validation in a Canvas Power App | Power Platform

Often times, you want to know the size of text entered in a field and want to indicate a user that they need to restrict the text to your specific size, like Twitter. And make sure the user is restricted within the limits. So, I’ve added a button to show that validation –


And you want to dynamically check the length as you type to see how much is remaining
And maybe also add some validation like disabling the button if the limit is reached

Let’s look at how we can implement this in Canvas Power App!


Let’s get to building this out!

  1. Let’s say you have a Text Input. I’ve simply called it “Message

  2. Then, I have the Label field called as “CharLength“. This will be a place holder for our counter of characters in the Message textbox.

  3. And finally, a Submit button which will be disabled if the Text size exceeds the limit.

Setting Properties

Now, let’s get the properties set to these components so as to validate the character limit

  1. Nothing to set on the Text Input ‘Message’ for this example.
  2. Let’s move to the label CharLength itself. Set the Text handler of the CharLength label control to the following (You can have your own limit)
    In the above example, I’ve set the length 60 and then I’m subtracting the length of the Text of the Message.Text (Text entered in Message box) so that as we type on, the remaining value will be shown as below –
  3. Now, let’s see the Color property of the text field. It’ll be a visual cue indicating the user that they’ve exceeded the character limit
    In the above example, I’ve added a condition to set the color as Red, if the length is exceeded or Black is the length is under the limit and will look something like below –

  4. Finally, we’ll go to the Submit button and set the Display Mode property of it to the below
    I’ve added a condition, that if the Length of the Message box’s Text goes above the limit, set the Display Mode to Edit i.e. Active or else, Disable. And it will look like below when disabled


This is how it will work when you put this in execution

And that’s it. So you can use this validation as you want. In place of the button, you could have something else put up.

Hope this helps!

Here are some posts on Canvas Power Apps you might want to check –

  1. Logged In User details in a Canvas Power App
  2. Implementing Exit app, Logout and Confirm Exit features in a Canvas Power App
  3. Get N:N records in a Canvas Power App using Common Data Service connector | Power Platform
  4. Variables in Canvas Power Apps | Global and Context
  5. Correctly connect to an Excel file in a Canvas PowerApp
  6. Adding a Canvas PowerApp to Teams
  7. Sending Image from Canvas PowerApps to SharePoint Document Library using Flows


Logged In User details in a Canvas Power App

You do get some details of the logged in user in a Canvas Power App. Let’s look at what all is available –


User() Function

User() function provides 3 pieces of information you can retrieve at this point in terms of logged in user.



Use User().Email to populate a Text field with the Email address of the logged in user.

Full Name

Use User().FullName to fetch the logged in user’s Full Name and maybe, populate it in a Text/Label field as well


Use User().Image to be able to populate the Picture control with the logged in User’s Picture. Remember, user needs to add this in their respective Office 365 account in order to appear here

User Details

Now, whenever a logged in user comes across these controls which we set above, the User details will vary for each user respectively. Below is how it looks for me.


You can obviously use it as and where it suits you.

Here are some more Canvas Power Apps posts you might want to look at –

  1. Variables in Canvas Power Apps | Global and Context
  2. Implementing Exit app, Logout and Confirm Exit features in a Canvas Power App
  3. Get N:N records in a Canvas Power App using Common Data Service connector | Power Platform
  4. Adding a Canvas PowerApp to Teams
  5. Sending Image from Canvas PowerApps to SharePoint Document Library using Flows

Hope this was easy and helpful!

Variables in Canvas Power Apps | Global and Context

For all newbies, being able to use Variables is one the most curious questions put out immediately. Here’s a simplistic example of using Variables, both Global and Contextual in this post.


Global Variable

Global Variables as the name suggest, run through the entire App itself and can be changed and altered when needed.
Global variables can hold boolean, string, number etc.

  1. Let’s say, I have a Text field called GuestNameField
  2. Global Variables are created and set by using Set(variable, value) function.

    Now, on the OnChange event of the GuestNameField above, I’m setting the variable by the formula Set(guestName, GuestNameField.Text). Where, guestName is the field I created on the fly and I’m setting the text from the GuestNameField textbox whenever the Textbox will trigger OnChange Event.

  3. And I have a Label called as DisplayValue which will read from the variable and set it’s text.
  4. Now, when I run the app and type the name, and when I release the focus on the text box, the
    And when the focus from the TextBox is released, OnChange of the TextBox will trigger and the Label will display the text written since it’s reading the value from the variable

Context Variable

Now, a variation to the Context Variable from the Global Variable is that the Context variable have the scope of the only the current screen they are declared in. Navigate function is also a form of Context variable in which case, you can pass values to other screens.

Context variables can hold strings, numbers, records and tables.

  1. Now, in case of Context Variables, you use UpdateContext({variable: value}) in the formula.
  2. And is accessed/read by simply writing the name of the variable directly
  3. And it behaves in the same way, you write something and it can be read
    And displayed below as seen in the above Global Variable example

Checking your Variables

In case you’re wondering you’ll lose track of your variables, you can check the File menu and access the Variables section as shown below

Global Variables as marked above can be accessed in their own section
And if you open any of those, you can see and even navigate to where they are used.

Similarly, for Context Variables are denoted by the Screen names they are in.

I tried to summarize this on a high level. You can refer this Microsoft Documentation for details Understand canvas-app variables in Power Apps.

Hope this was easy!

In case you are looking for more post related to Canvas PowerApps, here you go –

  1. Get N:N records in a Canvas Power App using Common Data Service connector | Power Platform
  2. Adding a Canvas PowerApp to Teams
  3. Correctly connect to an Excel file in a Canvas PowerApp
  4. Sending Image from Canvas PowerApps to SharePoint Document Library using Flows

Thank you!

Get N:N records in a Canvas Power App using Common Data Service connector | Power Platform

One of the most common asks when using CDS as Data Source in a Canvas Power Apps is – How do I get the data from N:N entities?

Well, I’m attempting to explain this in the easiest way possible.


Let’s assume Account entity has an N:N relationship with Account Plans entity

Account <–N:N–> Account Plans.

And in Dynamics 365, you simply add these records by going into related records and adding them using Add Existing button

And now, you want to access this data for a record in a Canvas Power App? Correct? Let’s get going with it.

Enable the Entities involved

In this example, the entities involved are Account and Account Plans

  1. Accessing data for N:N entities require the entities to be enabled for Change Tracking. Let’s check that in CDS
  2. And also the same thing for Account Plan entity as well

Reading Data in a Canvas Power App

I’ve kept the presentation of my Canvas Power App very crude, please excuse me for that.

Scenario: Now, let’s say you want to see the N:N data on selection of a record i.e. on selection of Account, you want to see what all Account Plans are added to that Account.

  1. Now, to demonstrate this, I’ve taken 2 galleries i.e. AccountGallery to show list of Accounts
  2. And probably a list to just display what Account Plans are added (You can have any other control depending on what you want to do with these records). I’ll call the table AccountPlansTable
  3. And my formula to display the N:N records will be –
    AccountGallery.Selected.’Account Plans’
  4. Now, you’ll need to add what fields should be shown from Account Plans entity to identify the records. Well, obviously, Name field is the most relevant here.
    I’ll click on Edit Fields for the AccountPlansTable
  5. And add the name field from that entity
  6. Once this is set, my App is ready to run

Accessing the N:N records

Let’s run the app and see how we can read these N:N records
Once I click on ABC/1/2&3, I can see the related N:N records in the DataTable below
Simple enough!

Here are some more posts you might like –

  1. Create your first PowerApp! Connect to SharePoint Online List
  2. Dynamics 365 Solutions’ New Experience in Power Apps, Solution Checker and more
  3. AutoNumber field in CDS | PowerApps
  4. Sending Image from Canvas PowerApps to SharePoint Document Library using Flows

Hope this helps!!

Adding a Canvas PowerApp to Teams

Let’s take a look at how you can simply export the Canvas App from your Organization and import it to Teams. And you should be good to go!

Exporting Canvas App

  1. Assuming you are an Admin and you have Owner/Co-Owner rights to the App, you can click the ellipses part on the App and look for Add to Teams option.
  2. Once done, you can check on the right hand-side to see some details and Download the zip file of the Canvas App when ready
  3. And that’s it, it gets downloaded like any other Model Driven/Canvas App solution file.


Importing App to Teams

  1. Now, you can import the same as a custom App in Teams. Navigate to the Apps section and look for Upload a custom app in menu as shown below.
  2. Now, chose the Org you want to import the solution file to. In my case, it’s just one organization, you may have multiple.
  3. A dialog box will pop up to ask you to select the solution file, navigate to the saved location and pick the file.
  4. And you’re ready. The App has been imported. You can see it in the Apps section under Built for CFT 146.


Adding App Per User

Each user needs to add the App themselves in order to be able to access it.

Also, remember that the user who is adding the App should have rights to access the App itself i.e. the App should be shared with those users.

Let’s say Kuldeep is another user in the CFT 146 Organization. He can explicitly search for the App and add it as below –

  1. Go to Apps, then look for the area, Build For <Org Name> and then look for the App that was imported.
    Attendees AppfindAppOnTeams
  2. Click on the App, and the dialog box will provide with a button to Add to Teams, along with other details mentioned alongside.
  3. Once added, it will appear next in the left navigation menu and you can simply run it by clicking on it.
  4. In case the user doesn’t have appropriate rights on the App, they will see this message when trying to open the App in Teams.

Hope this helps!! Happy 365ing!