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 –


undefined

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

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

Setup

Let’s get to building this out!

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

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

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

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)
    undefined
    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 –
    undefined
  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
    undefined
    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 –
    undefined

  4. Finally, we’ll go to the Submit button and set the Display Mode property of it to the below
    undefined
    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
    undefined


Execution

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

Thanks!!

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 –

undefined

User() Function

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

undefined

Email

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

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
undefined

Image

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
undefined
undefined

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.

undefined

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!

Loop through array of objects in a Flow & Create records in CDS | Power Automate

One of the most common scenarios that are looked out for are ways to loop through an array of objects received (say, from HTTP response) and create CDS records

Sample Data

Let’s say this is the sample data coming in which is an array of objects. This is coming from my HTTP trigger which I created and hosted. It could be anything else in your case
undefined

And the body looks something like this –

[{"Name":"FreshBeans Coffee","City":"Mumbai","Phone":999999999},{"Name":"Timber Mart","City":"Pune","Phone":999999999}]

Generate Schema from Payload

I need to first create the Schema to be able to easily read from the JSON response
undefined

Paste a sample Payload in the dialog box
undefined

And it will generate a Schema
undefined

And when this is generated, you can access the attributes further in your Flow
undefined

What if you just enter a blank object and not generate from Schema or enter Schema explicitly as shown below –
undefined
You won’t get the attributes from the JSON Payload which is needed further
undefined

Loop through array and Create in CDS

Now, you can use Apply To Each and pass the Parsed JSON Body. I’ve simply used Compose to see the entire Object while checking results (No other purpose of using Compose in this example)
undefined

And then the next step is to Create CDS records from the looped Objects. So, since I have the schema generated above, I can use the attributes to directly map it to the CDS Create Record action

undefined

Running the Flow

Finally, once I run the Flow and check the actions performed. I’ll create 2 records since there are 2 objects in my array.

I’ll see the Compose step to see what I got in the object. As I mentioned earlier, this is not required- I just intend to put it there to see what data came in
undefined

And the Create Record in CDS step will create record in my Dynamics 365 environment as I intended it to do –
undefined

I can check the same in Dynamics 365
undefined

You might also want to check other posts related to Power Automate –

  1. Get Count of records retrieved in CDS connector in a Flow | Power Automate
  2. Number Formatting in a Flow | Power Automate
  3. Call a Dynamics 365 Action from Flow [Bound and Unbound Actions] | Power Automate
  4. Switch-Case in a Flow | Power Automate
  5. Setting Retry Policy for an HTTP request in a Flow | Power Automate
  6. Make HTTP request from Flow in Power Automate
  7. Button Flow in Power Automate to replicate a Quick Create Form in D365 CE
  8. Enable Flow button on D365 Ribbon

Hope this was easy!

Implementing Exit app, Logout and Confirm Exit features in a Canvas Power App

Most common scenarios are where you need users to be able to Exit the Canvas Power Apps in the below ways –
Scenario – Let’s say you put a close button somewhere in your App.
undefined

  1. Exit the current App but stay logged-in to Power Apps.
  2. Exist and Logout Power Apps entirely.
  3. In both above cases, ask user for confirmation before exiting.

So let’ look at these scenarios one by one –

Exit from current App

  1. Now, let’s say you’ve put a Close button on your App like this. And when you click it –
    undefined
  2. It takes you to the App selection screen in your Power Apps
    undefined
  3. You can implement this using Exit() method on OnSelect property of the Close button as shown below
    undefined

    And that’s it.


Exit and Logout of Power Apps

  1. Another variation to the same feature would be to Exit the App as well as Logging out completely. Now, I’ve put a Lock button here to represent Logout.
    undefined

  2. You can implement this by using Exit(true) method as shown below
    undefined
  3. And, it will logout the PowerApps Application itself.
    undefined
    And you’ll need to log in all over again.

Confirm before Exit

This is a feature that will work with both, Exit() and Exit(true). It will ask you for a confirmation on whether if you really like to close/logout the app?

  1. Select App in the left-hand Tree view, select App
    undefined
  2. And look at the right hand Properties menu – The Confirm exit and Confirm exit message will let you enable this feature with the message you want to display –
    undefined

    And you can set your message
    undefined
  3. And then, when you either Logout or try to Close the App, you’ll be prompted with this message
    undefined

And it’s all that simple! In case you are looking for more articles on Canvas Power Apps, you might want to check these below –

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

Hope this helps!

Get Count of records retrieved in CDS connector in a Flow | Power Automate

In several applications, you need to know how many record were retrieved in the List records Action in a Common Data Service connector in order to take a decision.

Scenario

Typically, let’s say I know only 1 record should exist in order to take that record forward and do an action. But how do I know when only 1 record was received? That’s when you use Control

Check Count

Now, let’s say you want to want to retrieve Accounts and know how many were returned (Perhaps, you want to proceed only if at least 1 or more were retrieved)

  1. This is my List Records action and I’ve named it as Get All Records.
    defaultListRecords
  2. And just to display how many records are retrieved, I’ll use a variable. Usually, you would use this in condition (which we’ll get to in a bit)
    initVar
  3. So, in the expressions to set the Variable, under Dynamic Content, I’ll write –
    writeHereand write the below expressioncountactualExpression
    which is set to the variable
    setVar
  4. And here are the results. I have 101 Accounts
    count

Using it for comparison

This is one of the typical use cases where you want to proceed only if you have at least 1 record –
typicalUseCase

Here are some more Flow related topics you might want to take a look at –

  1. Number Formatting in a Flow | Power Automate
  2. Get N:N records in a Canvas Power App using Common Data Service connector | Power Platform
  3. Switch-Case in a Flow | Power Automate
  4. Setting Retry Policy for an HTTP request in a Flow | Power Automate
  5. Retrieve only active Dynamics 365 CE licensed Users in CDS connector in Power Automate
  6. Button Flow in Power Automate to replicate a Quick Create Form in D365 CE
  7. Make HTTP request from Flow in Power Automate
  8. Create a To-Do List Item of Important Outlook Emails using Power Automate

Hope this quick tip helps!

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.

headerImg

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
    guestFieldAdded
    guestNameFieldView
  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.
    formulaWritten

  3. And I have a Label called as DisplayValue which will read from the variable and set it’s text.
    readFromVar
  4. Now, when I run the app and type the name, and when I release the focus on the text box, the
    typeName
    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
    appear

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.
    contextVar
  2. And is accessed/read by simply writing the name of the variable directly
    directContextVarName
  3. And it behaves in the same way, you write something and it can be read
    typeName
    And displayed below as seen in the above Global Variable example
    appear

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
menuItem

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

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

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!

Number Formatting in a Flow | Power Automate

Quite obviously this is one of the most common asks in Flow to format a number. Here are some ways to do so using Format number Action in Flow (Power Automate).

This is available in Format number action in a Flow in Power Automate. This is available in Number Functions connector.
numActions

Commas and Decimals

  1. For a standard simple number, you can simply denote by # and commas or other symbols where needed. Here, I won’t select any locale.
    standardNumberBody
  2. And it would render into this –
    standardNumber

Phone Number

  1. US phone is an example where it is denoted by brackets and dashes in between. I’ll select English (United States) (en-US) in the locale among others. So, my format would be.
    isPhoneBody
  2. And the resultant phone number will be set as below
    usPhone

Currency Input

For currency, this is what I did –

  1. Added ₹ followed by ##,###,###. I’ll select English (India) (en-IN) in the Locale field.
    indCurrencyBody
  2. So even though my number value i.e. (50000) is in thousands and not hundred-thousands as I covered in my format, it’ll consider the correct format used and my output will be – indCurrency

Here’s where you can look at other ways to format numbers –
1. Standard numeric format strings
2. Custom numeric format strings

If you’re looking for some more posts on Flow / Power Automate, I’ve written some in the past. Check these –

  1. Create a To-Do List Item of Important Outlook Emails using Power Automate
  2. Get N:N records in a Canvas Power App using Common Data Service connector | Power Platform
  3. Call a Dynamics 365 Action from Flow [Bound and Unbound Actions] | Power Automate
  4. Switch-Case in a Flow | Power Automate
  5. Setting Retry Policy for an HTTP request in a Flow | Power Automate
  6. Make HTTP request from Flow in Power Automate
  7. Using Parse JSON to read individual List Records in Flow|Power Automate
  8. Secure Input/Output in Power Automate Run History
  9. Button Flow in Power Automate to replicate a Quick Create Form in D365 CE
  10. Enable Flow button on D365 Ribbon

Hope this helps!