Category Archives: Canvas apps

Set Date Picker in Canvas App to today’s date by default

Follow my blog for more interesting topics on Dynamics 365, Portals and Power Platform. For training and consulting, write to us at info@xrmforyou.com

This one will be real quick. A small and effective one I should say. But before we go into the solution, let’s understand the problem statement here.

My customer have a canvas app built on Common Data service (CDS). The canvas app has an edit form for the contact entity. There is a date field on the Contact form.

Canvas app set default date for date picker.

You might have already noticed the issue here. This is the edit form for contact record. The date field is set to default value – 12/31/2001, if the field is empty. A close look at the DefaultDate property of the Date picker field reveal it is set to Parent.Default

Canvas app set default date for date picker.

Also if you observe carefully, the date is actually greyed out. It’s actually more of like a placeholder value but nonetheless annoying.

Recent Posts

In this blog, we are going to set the default date, in case the date field is empty, to today’s date. Let’s tackle these scenarios one by one. The first thing is to go ahead, select the data card for the date field and Unlock the data card to change it’s properties.

Canvas app set default date for date picker.

Once we do that, the next step is to select the date picker and set the DefaultDate property to the below formula.

Canvas app set default date for date picker.

Formula Text

If(IsBlank('Date field'), Today())

I set the field to Today’s date using Today() function if the field is blank. The below screenshot show the formula in action.

Canvas app set default date for date picker.

Simple and yet a requirement that pops up every now and then.

Hope this helps!

Debajit Dutta
(Business Solutions MVP)

Restrict File Type in Attachment control in Canvas App

Follow my blog for more interesting topics on Dynamics 365, Portals and Power Platform. For training and consulting, write to us at info@xrmforyou.com

This one is pretty cool and it was delight to achieve this. The requirement here is pretty simple. Customer have Dynamics 365 instance and they have a canvas app with Dynamics 365 (CDS) as datasource. In CDS datasource, we have support for File Attribute where you can upload attachment for record.

HostGator Web Hosting

Below is a contact form of CDS with the File attribute in action.

Attachment control in Canvas app.

The file attribute is displayed in “Attachment” control inside a canvas app. Now the requirement. We need to restrict the attachment type to only .pdf and .docx files. So let’s see how we can achieve this.

It’s actually quite easy. There is an event for attachment control – OnAddFile. To restrict file type, we need to attach a event handler for the OnAddFile event.

Check out my other posts

In the OnAddFile event, I write the below formula.

Restrict File Type in Attachment control - Formula

Text representation of the formula:

If(Not(EndsWith(First(Self.Attachments).Name, ".pdf")) And Not(EndsWith(First(Self.Attachments).Name, ".docx")),Notify("Only pdf and docx files are allowed", NotificationType.Error); Reset(Self))

Quick explanation of the code. I am checking if the file extension is neither .pdf or .docx. If neither is the extension, I am using the Notify function to show error message to the user.

Restrict file type in attachment control in canvas app.

And there you go! It’s like what I expected. Cool stuff.

Hope this helps!

Debajit Dutta (Business Solutions MVP)

Associate and Disassociate records in Power Apps Canvas Apps

Follow my blog for more interesting topics on Dynamics 365, Portals and Power Platform. For training and consulting, write to us at info@xrmforyou.com

With every new release of Canvas apps, Microsoft add new features to it’s kitty. Today I will explain one of these features. And that is the ability to associate records in Canvas apps. I am going to walk you through on how we can associate and disassociate entity records in 1:N and N:N relationship.

One to Many

For this demo I have built a small canvas application. The application shows both the Accounts and Contacts list.

Relate records in Canvas apps

When the “Associate” button is clicked, it will associate a contact to the account record. And we can do this using the Relate() function in canvas apps.

In “OnSelect” event of the associate button, I use the below formula.

Relate formula canvas apps
BrosweGallery 1 – Accounts. Gallery1 – Contacts

It’s pretty easy I guess to understand what the function does. I take the selected item from Account gallery and then specify the relationship name. The second parameter of the function take the child record. Hence I have used the selected contact from Contacts Gallery in the second parameter.

When I click the Associate button, magic happen. The contact record is now associated with the account.

Similarly to disassociate, we need to use the Unrelate() method. The Unrelate function has a similar nomenclature like the Relate function. Below is the formula to disassociate contact from the account record.

Unrelate function in Canvas Apps

Many to Many

The syntax for many to many relationship is actually the same as one to many. The only difference is with many to many, we can use the Relate function and Unrelate function with both the participating entities. So for an account and contact in N:N relationship, to associate a contact with the account, I use the below code.

Relate(<AccountRecord>.'Contacts', <ContactRecord>)

Similarly to associate an account with the contact, I use the below code

Relate(<ContactRecord>.Accounts, <AccountRecord>)

Hope this helps!

Debajit Dutta

Debajit Dutta

Solutions Architect

XrmForYou Consulting Private Limited

Email : info@xrmforyou.com

Manage versions and Restore Canvas App version

Follow my blog for more interesting topics on Dynamics 365, Portals and Power Platform. For training and consulting, write to us at info@xrmforyou.com

In this blog, I am going to walk you on how to manage version in Canvas app. Also I am going to discuss on how we can restore a canvas app to it’s previous version, if required.

Before I go ahead and explain things in depth, I will explain versioning in Canvas app. Whenever a canvas app is created using PowerApps Studio, a version of the app is automatically created. Below is a screenshot from my PowerApps studio, once I create an app for the first time.

Canvas app version.

As in the above screenshot, there is an option to “Sell all versions”. If I click on this button, it takes me to the screen below.

Live Canvas app version.

What’s important here is the Version number (currently showing “Version 1”) and Published Column showing “Live”.

Now let’s dig a little deep. I make further changes to the canvas app in PowerApps studio. And each time I save, it creates a new version of the app. This is quite interesting. Check for the screenshot below.

Multiple canvas app versions.

As you see in the above screenshot, it created a new version – Version 2. However, that version is not live yet. In this way I can go ahead and save as many time I wish.

Now that’s clear. But how do a new created version of the app go Live? To do that, I select the version and click on Publish. And that version goes live.

Publish specific version in Canvas app.

So that’s cool. But we have one more problem to solve. And what is that? How to restore a previous version?

Before I go ahead and explain how to do it, let’s understand the scenario when you need to restore an app to it’s previous version.

Suppose I have added quite a few new features in my app and then publish it. However user’s are facing issue once the version has been rolled out. In order to make sure that users are not stuck, I decide to roll back the app to the previous version. In the below screenshot, Version 2 is Live.

Restore version in Canvas app.

If I want to rollback to Version 1, all I need is to select Version 1 and then click on Restore.

Restore version in Canvas app.

And that’s it. I am back to the previous version.

Hope this helps!

Debajit Dutta

Solutions Architect

XrmForYou Consulting Private Limited

Email : info@xrmforyou.com

Get Current User Information in Canvas Apps.

Follow my blog for more interesting topics on Dynamics 365, Portals and Power Platform. For training and consulting, write to us at info@xrmforyou.com

The introduction of Canvas Apps have completely changed the way of developing apps. App development was always a developer’s paradise. With canvas apps, it’s a level playing field for developer and Power Users alike. And that’s why, I find more and more users from company joining the bandwagon.

And toeing the line, am back with another blog on Canvas apps. In this blog, I am going to walk you on how to get currently logged in User related information in Canvas Apps. Canvas apps provide an in-built method – User() to fetch user related information in Canvas apps. Let’s explore the various functionalities available with User() function.

For this blog, I have created a sample Canvas app to show User related information. Let’s find out the important ones.

  1. Image

The first important property of the User() function is to show the image of the current user. You may be wondering, OH MY GOD! Not one more time with the byte content. The truth is, with Canvas apps, all you need to show the image is a property called Image of the User Function.

In the above screenshot, I have used the Image field on the form and set it’s Image property to the formula – User().Image. Similarly there are other properties like FulName and Email which you can use with the User() function.

As crazy as it may sound, some of the commonly used properties like first name, last name etc. are not available in User() function as of the time of writing this blog. However I am quite sure that in the future, we will see improvements in this API as well just like it happened with so many other API’s.

Related topics

Hope this helps!

Debajit Dutta (Business Solutions MVP)

Get Today’s date, format dates in Power Apps Canvas app

Follow my blog for more interesting topics on Dynamics 365, Portals and Power Platform. For training and consulting, write to us at info@xrmforyou.com

Working with date and time values are one of the most common requirements across implementations irrespective of the technology and the same applies to PowerApps canvas apps.

And Canvas app have power functions in it’s kitty. It has the following functions

  • Now() – displays the current date and time
  • Today() – displays today’s date without the time. The time is always set to midnight 12:00 AM
  • IsToday() – Check if a date specified is today’s date. The function will return true from midnight of current day to the midnight of the next day.

So if you want to compare a date value to check if it’s today’s date, no need to compare between Now() and Today(). Use the function IsToday()

Now that we know the powerful functions inside canvas apps, it’s time to understand how to display date values in specified format. Below is a screenshot of how to do the same. You can pass specific predefined formats.

image

If you are not happy with the predefined formats, no need to worry. You can specify the format of your choice.

image

As you can see in the above screenshot, we can specify any format as desired.

Hope this helps!

Debajit Dutta

(Business Solutions MVP)

Use Navigate() function to pass data between two screens in PowerApps Canvas apps

Follow my blog for more interesting topics on Dynamics 365, Portals and Power Platform. For training and consulting, write to us at info@xrmforyou.com

Every now and then when you design a Canvas App, you may be required to accomplish the following requirements.

  • Pass data from one screen to another while navigating to the new screen.
  • Identity from which screen the user arrived on the current screen.
  • Contextual information that need to be shared only between two specific screens.

In canvas app, Navigate() is the function which is used to navigate from one screen to another. And while not known much, Navigate() function in-fact has an additional construct to pass contextual data to the next screen.

image

Pic courtesy : Microsoft Docs.

So let’s see how we can pass data between two screens. Below is the formula OnSelect of a button where we are browsing to the BrowseScreen1 and also passing in two variables

  • Variable1 – String value
  • Variable2 – Boolean Value

image

The method is similar on how we set a screen variable using UpdateContext() function. The very good thing with this Navigate() construct is the variables will only be available in BrowseScreen1. This is very helpful to pass the contextual information from one screen to another instead of using the Set() function which makes the variable accessible across all screens.

Hope this helps!

Debajit Dutta

(Business Solutions MVP)

Specify more than one JSONFormat value inside JSON function in canvas app

Follow my blog for more interesting topics on Dynamics 365, Portals and Power Platform. For training and consulting, write to us at info@xrmforyou.com

This one is a really simple trick which is required in so many. How can I specify multiple JSONFormat values inside JSON() function in canvas app?

Before I go ahead and provide an answer to it, it’s important to understand the scenarios when you need to specify multiple JSON formats. There can be so many situations but I can give you a real life example that we were trying to achieve.

We were trying to serialize CDS entity data into JSON variable. So basically it was the Accounts entity data. We wanted to serialize the data into JSON but not include the Image data types. So basically we need to exclude Binary data (for image fields). Well it was simple. Below is the formula we wrote. But to no luck.

image

We got an error – “The JSON function cannot serialize tables / objects with a nested property called ‘_ownerid_value’ of type ‘Polymorphic’”.

The error clearly states that it is not able to serialize the lookup fields like ownerid, primarycontactid etc. That’s fine, there is a JSON format value to include Unsupported types. But how to specify it. After all we have already specified IgnoreBinaryData.

Well it’s an easy trick. All you need to do is use the ‘&’ operator to concatenate the two formats and in-fact you can use as many you want.

image

And now it works like a charm.

Hope this helps!

Debajit Dutta

(Business Solution MVP)

How to get the value (not text) of a selected option for a CDS Option Set in Canvas APP

Follow my blog for more interesting topics on Dynamics 365, Portals and Power Platform. For training and consulting, write to us at info@xrmforyou.com

Canvas apps have really taken the art of developing pretty neat apps for mobile platforms from a niche set of developers to a wide platform of developers, consultants and business users. And with Microsoft adding features to the Power platform framework every now and then, I don’t find any reason for this to not be in forefront of B2B apps in the days to come.

And yet among so many features provided by the platform, we come across a requirement which is pretty basic and to our surprise we find it’s not a cakewalk like we thought. And one of this requirement is to get the value of a selected option from a CDS option set in Canvas app.

So let’s see the problem here.

As you can see the below screenshot, it is from Account Entity and I have included the “Industry” field which is an optionset.

Below the Industry field, I have a label which shows the value of Industry selected.

image

As you can see, the formula is “ddlIndustry.Selected.Value”. Where ddlIndustry is the name of the dropdown control. As you can see it is printing the text of the selected Item. I tried many ways but unfortunately everytime I ended up getting the Text value. But what if I wanted to get the underlying value instead of text.

image

Well there is way. And surprisingly this is the wonderful JSON() function which you might have already used in so many places for so many purpose but never thought it could actually help you with this requirement also. So let’s see how we can do this.

In the OnChange event of the dropdown control, I use a formula to store the value of the selected item inside a variable

image

And the rest is all to easy. I now use this variable to set the label text.

image

And now when I run, I get the underlying value instead of text.

image

Awesome isn’t it. Such a simple trick which escaped our eyes for so long.

Hope this helps!

Debajit Dutta

(Business Solutions MVP)

Designing Business process flows for your canvas apps

I had this requirement lately and the first time I heard this I thought, is this even possible? But then I never doubt about the every increasing capability of canvas apps. So decided to do a search.

And guess what! Found this wonderful documentation here with a complete solution.

Advertisements

https://powerapps.microsoft.com/en-us/blog/using-business-process-flows-in-a-canvas-app/

I am simply falling in love with PowerApps documentation which is so much focused on implementation and solutions rather than just theory.

Towards the end of the solution, you will find a link to download the powerapps solution sample. Link – https://github.com/microsoft/powerapps-tools/blob/master/Apps/BusinessProcessFlow/BPF_Solution_1_0_0_11.zip

Advertisements

One point to note here – The BPF Component shown in the blog is not an OOB control available but in fact it is a generic control custom built for designing a BPF. So if you are searching a control with that name in your powerapps component list, you may not get it.

Hope this small tip helps!

Debajit Dutta

Business solutions MVP