Recover deleted D365 PowerApp environment using PowerShell

To get the most important things out of the way, this can be done only within the first 7 Days.

Deleted Environment

At times, you want to delete an environment you don’t need. But you feel you do need it back. Deleting an environment from the Power Platform Admin Center will Soft Delete it and you can get it back within the first 7 days only.

Here’s some info by Microsoft on that: https://docs.microsoft.com/en-us/power-platform/admin/backup-restore-environments#how-long-are-my-manualon-demand-backups-and-system-backups-retained

Here’s what we can do within the first 7 days to get it back using PowerShell!

Get PowerShell Support for PowerApps

Before we are able to Run PowerShell directly to recover, you’ll need to get the support for PowerApps in your PowerShell first.

Refer this full Microsoft Documentation for full details: https://docs.microsoft.com/en-us/power-platform/admin/powerapps-powershell#power-apps-cmdlets-for-administrators-preview

  1. Open PowerShell and remember to Run it as as Administrator.



  2. Here’s how you can install the capabilities

    And then

    Here are the 2 commands which I used in the screenshots above in PowerShell. Below is the screenshot I took from Microsoft Docs so that you can visualize how the commands look
  • Install-Module -Name Microsoft.PowerApps.Administration.PowerShell
  • Install-Module -Name Microsoft.PowerApps.PowerShell -AllowClobber

    or if you don’t have Admin Access, below code can be used in PowerShell
  • Save-Module -Name Microsoft.PowerApps.Administration.PowerShell -Path
  • Import-Module -Name Microsoft.PowerApps.Administration.PowerShell
  • Save-Module -Name Microsoft.PowerApps.PowerShell -Path
  • Import-Module -Name Microsoft.PowerApps.PowerShell


4. Now, let’s say you are all set to execute your recovery process.

Recovery of Environment

Assuming you have completed the above steps, you can now proceed towards recovering the environment.

  1. Now, in PowerShell, run the below command “Get-AdminPowerAppSoftDeletedEnvironment

  2. You’ll be directed to a Login screen. Enter environment credentials there.


  3. You’ll get the Deleted environments’s details as below. In my case, only 1 Deleted environment was retrieved

    Note the first line i.e. EnvironmentName. Copy that GUID

  4. Next, run the below command after you copied the GUID –
    Recover-AdminPowerAppEnvironment -EnvironmentName 35545668-80c2-4d88-811d-b698bb1bcf59 -WaitUntilFinished $true

  5. Once completed, you won’t see any message but the cursor will be on the new line ready. And some details about the success of the operation.

  6. And in the Admin Center, the environment will be recovered.


    Hope this helps!!


    Here are some more Power Platform related posts you might want to check –
    1. Create new Sandbox and copy Production over to it in PowerPlatform Admin Center
    2. New ‘Capacity’ analytics on PowerPlatform Admin Center
    3. D365 Admin Center: Instance Picker Link

Thank you!


Launch URL on a Data Table Text column selection in a Canvas PowerApp | SharePoint Lists

Let’s say you are using SharePoint Lists to populate your Data Table in a Canvas Power App. And you have a Text column which could be typically name of the Website and another column could be a URL.

Now, you want to be able to click the Name of the Website and the selection should take you to the Website itself.

Scenario

Now, below is the Blog List in SharePoint you are populating your Data Table in a Canvas App with.

Now, I’ll use the above list to populate the Data Table to only show the Title in the Data Table and make the names clickable so that the URL of these Website names should be navigated to when you click them

Data Table column

  1. Firstly, the Names of the Blogs will appear in Plain Text because in SharePoint, this field is of Type plain text.


  2. In order to convert them to hyperlink, select the column as shown below


    And then, on the right hand side in Table Column Properties, turn on the Is hyperlink flag to On

  3. Now, the names will be clickable

Now, these Titles should be clickable and navigate to the URL which is mentioned for each of these Website Names.

OnSelect property and Launch Function

  1. Every Data Table column has an OnSelect property which you can set.

  2. Now, you can use the Launch() function to launch a URL which in this case will launch/open the data from the URL column of the Data Table (which we have not displayed anywhere in the Data Table)


    Now, here’s what the above Formula is set as
    Launch() will accept Text values. The “BlogList Data Table” is the name of the Data Table we are using i.e. the SharePoint List.
    .Selected will consider the Row we will click/select.
    And URL is the name of the column where the URL resides.
    Hence, it’ll Launch the URL we specified again each website name.

Working

When you open the App, and click on the name of the Site


Hope this was useful!!

Here are some more Canvas Power Apps posts you might want to check out

  1. Aggregate functions in a Canvas Power App | Using on SharePoint Lists
  2. Count of total CDS records returned in a Canvas Power App connection [Quick Tip]
  3. Dependent OptionSets in a Canvas Power App for 1:N related CDS entities | Power Platform
  4. Restore older version of a Canvas Power App | Power Platform
  5. Implement character length validation in a Canvas Power App | Power Platform
  6. Logged In User details in a Canvas Power App
  7. Implementing Exit app, Logout and Confirm Exit features in a Canvas Power App
  8. Variables in Canvas Power Apps | Global and Context
  9. Get N:N records in a Canvas Power App using Common Data Service connector | Power Platform
  10. Adding a Canvas PowerApp to Teams

Thank you!


Aggregate functions in a Canvas Power App | Using on SharePoint Lists

Aggregate functions have one of the most common applications while building your Canvas Power App.

In this simple example, we’ll try to make common Aggregate Functions like Max, Min, Sum & Average work.

There are 2 more advanced Aggregate Functions, StdevP for Standard Deviation and VarP for Variance. (It might not make full sense in this post, but I added them anyway to see how we can apply for formula 😊 I’m sure your use-case will make more sense!)

SharePoint List

Let’s say, my SharePoint list looks like this. Scores of some people and their ranks

And I’m using Data Table to populate this into my Canvas Power App

Formulas

Here’s how I used for Formulas to use the Aggregate functions on the SharePoint list data I populated in my Canvas Power App

For all the Formulas above, I’ve written them inside a Concatenate function just so I could add some Text and then use the formulas. You may use differently.

In my case, the Formula goes like this –
Function(SharePointListName, ColumnName)

“Max” – Maximum Number in Score column of Scoreboard list


“Min” – Smallest Number in Score column of Scoreboard list

“Sum” = Total of all values in Score column of Scoreboard list

“Average” – Average of all values in Score column of Scoreboard list

“StdevP” – Standard Deviation arguments passed. Score column in this case

“VarP”-Variance of the arguments passed. Score column in this case

And that’s it! I tried to simply the explanation. However’s there much more to consider as well. Here’s the full documentation by Microsoft – https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-aggregates

You might want to check some posts on Canvas Power Apps as well –

  1. Count of total CDS records returned in a Canvas Power App connection [Quick Tip]
  2. Dependent OptionSets in a Canvas Power App for 1:N related CDS entities | Power Platform
  3. Restore older version of a Canvas Power App | Power Platform
  4. Implement character length validation in a Canvas Power App | Power Platform
  5. Logged In User details in a Canvas Power App
  6. Implementing Exit app, Logout and Confirm Exit features in a Canvas Power App
  7. Variables in Canvas Power Apps | Global and Context
  8. Get N:N records in a Canvas Power App using Common Data Service connector | Power Platform
  9. Sending Image from Canvas PowerApps to SharePoint Document Library using Flows
  10. Correctly connect to an Excel file in a Canvas PowerApp

Hope this was helpful!

Count of total CDS records returned in a Canvas Power App connection [Quick Tip]

Like in Dynamics 365, you see a total number of records under a view. And you want similar in a Canvas PowerApp too.
undefined

Here’s a simple tip to do so –

CountRows() method

It’s pretty simple. Using CountRows(source) method, you can get the count of records in the Source. In this case, it’s the CDS entity Accounts.
undefined

To flourish how I display the count, I use the Concatenate() method and then use CountRows() inside it first show the text and then the actual count.

Please note that this goes without filtering out any criteria and straight count of how many records the connection has. Your gallery could use more filtering to display lesser records if specified that way.

Handle Delegation

However, you need to handle a few things if you’re aware that your dataset is large.

Using this formula will give a warning:
undefined

And the general help offered is this –
undefined

Refer this article to understand more: https://powerapps.microsoft.com/en-us/blog/powerapps-data-row-limit-for-non-delegable-queries/

Hope this quick tip helps!

Here are some more Canvas PowerApp / Power Automate posts you might want to look at –

  1. Dependent OptionSets in a Canvas Power App for 1:N related CDS entities | Power Platform
  2. Restore older version of a Canvas Power App | Power Platform
  3. Implement character length validation in a Canvas Power App | Power Platform
  4. Logged In User details in a Canvas Power App
  5. Implementing Exit app, Logout and Confirm Exit features in a Canvas Power App
  6. Variables in Canvas Power Apps | Global and Context
  7. Get N:N records in a Canvas Power App using Common Data Service connector | Power Platform
  8. Get Count of records retrieved in CDS connector in a Flow | Power Automate

Thank you!

Dependent OptionSets in a Canvas Power App for 1:N related CDS entities | Power Platform

Most useful scenarios is to create what we commonly call as “Dependent OptionSets” in Dynamics 365 context.

Scenario

Here, Country and State are 2 entities in CDS. Each Country has N states i.e. Country is a parent entity of State entity.
undefined

We’ll create 2 Drop-downs in a Canvas Power App i.e. 2 OptionSets namely Country and State that selection of Country will affect what should be populated in State entity. Simple!
undefined

Setting up your Drop-down controls

Let’s see how the drop-downs are set.

  1. Drop-down 1 is populated from Countries entity in CDS (Common Data Service)
    undefined

    undefined
  2. For State to be filtered based on the Country, we’ll use Filter() function to show records based on what Country is selected in Drop-down 1.
    For Items of the Dropdown2 control, we’ll write the below formula
    undefined
    undefined

    So, the Filter([EntityToPopulate], ‘[LookupFieldNameOfParent]’.[EntityOfParent]) = [DropdownControl].Selected.[GUIDFieldOfParentEntity])
    Sorry, it’s a little rough on the eyes!
  3. And it will give you the below. Select Country first
    undefined

    select your parent record
    undefined


    Then, the drop down will populate child records based on the Country. So the States will show up which have lookup to India as Country.
    undefined

And that was it!

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

  1. Restore older version of a Canvas Power App | Power Platform
  2. Implement character length validation in a Canvas Power App | Power Platform
  3. Logged In User details in a Canvas Power App
  4. Implementing Exit app, Logout and Confirm Exit features in a Canvas Power App
  5. Variables in Canvas Power Apps | Global and Context
  6. Get N:N records in a Canvas Power App using Common Data Service connector | Power Platform
  7. Adding a Canvas PowerApp to Teams
  8. Sending Image from Canvas PowerApps to SharePoint Document Library using Flows

Hope this helps!!

Restore older version of a Canvas Power App | Power Platform

When you users report of an issue and you need some time to look into it but can’t hold the users, you just want to restore to a previous version for the time being.

Here’s how you can restore/revert to an older version of the Canvas App you’ve deployed.

Current Version

Let’s say my current version had a button called Profile under the label Accounts. But in the new version, I had moved it and now want to restore the previous one for some reason.

undefined

This previous version is what I want to restore to.

undefined

Restore & Publish

Here’s how you can Restore it.

  1. Navigate to Save, and go to See All Versions
    undefined

  2. Now, you’ll come to all the versions of the App existing. The current one will have the status of Live. Click on the three ellipses of the old version of App you wish to restore and you’ll see an option to Restore
    undefined

  3. It’ll ask for a confirmation. Remember, the new version will be 1 version higher that the current Live version. In this case, it’ll be version 18 to be created from version 16 (version 17 is the current Live version)
    undefined

  4. Once you confirm, a new version will be created. This is not yet in Published stage. This is because you might want to go back and change something and then Publish
    undefined

  5. Now, let’s say you are ready to Publish, simply select it. And then either from the options in ellipses or on the top ribbon, you can Publish this version
    undefined

Update on App

Upon opening the App, the user will see a message like this
undefined

And when you tap on it, the previous version is restored
undefined

Pretty easy!!

Here are some more Canvas Power App posts you might want to check –

  1. Implement character length validation in a Canvas Power App | Power Platform
  2. Logged In User details in a Canvas Power App
  3. Implementing Exit app, Logout and Confirm Exit features in a Canvas Power App
  4. Variables in Canvas Power Apps | Global and Context
  5. Get N:N records in a Canvas Power App using Common Data Service connector | Power Platform
  6. Adding a Canvas PowerApp to Teams

Hope this helps!

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!

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!

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!