Tag 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)

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

How to reset controls inside Gallery 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

Lately designing quite a few canvas apps for specific modules and this is one issue we faced recently while working for a customer.

So the customer had a gallery control which was bound to CDS contacts and then there were some additional controls like Checkbox, Text inputs etc for each gallery item where end-users can make their choices.

Advertisements

While the actual screen looked much different, this is the mockup I came up for this scenario.

image

They wanted a reset functionality i,e when the reset button is clicked, the controls inside the gallery should be set back to their default  values. In other words in the example here the text inputs should be cleared and checkboxes should be unchecked.

Piece of cake we thought and out in the code on click of the Reset button

image

Well it didn’t work. And then tried something more stupid

image

Quite obvious, it won’t work. But why? A bit of search but this Microsoft Documentation just helped our understanding. This documentation on PowerApps Reset function is just what we we needed. If you go to the link, you would find this statement – “You cannot reset controls that are within a Gallery or Edit form control from outside those controls. You can reset controls from formulas on controls within the same gallery or form”

Advertisements

Quite obvious, the Reset button was outside the gallery and hence invoking Reset from there didn’t work. But is there a way out? Off-course there is one certainly and much easier than you may think.

So let’s first focus on the text input control inside the gallery item. There is a “Reset” property of the input item.

image

We are going to set it to a context variable however you can use App level variable as well which can be set using “Set” function.

image

You may get an error. that’s fine. This is because we haven’t yet declared the context variable.

Advertisements

Now on-select of the button you can write the below code.

image

Quite understandably, ResetTextInput when set to True, it would reset the text input to it’s default value. However you may ask the question – Why are we setting it to false? The reason for this is for the next operation when you click on the Reset button, it will again change the value from Context variable from false to true. Once a value change is detected by the framework, the Reset function would fire again.

If we don’t set to it to false post reset, it won’t work.

The same you can do for your checkbox. You can use the same variable or a different variable.

A simple one but can save you some time if you are not aware of it.

Advertisements

Hope this helps!

Debajit Dutta

(Dynamics MVP)

For consultation/ corporate training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com

Our product offerings:

Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)

CRM-Sharepoint Attachment uploader and metadata manager (http://www.xrmforyou.com/sharepoint-integrator.html)

Record Cloner for Dynamics 365 (http://www.xrmforyou.com/record-cloner.html)

Update a record in CDS/ Dynamics 365 from canvas app without using primary key

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

I have recently been conducting some trainings on canvas apps and one of the questions that came up during the session was regarding the Patch function in canvas app.

As the name suggests, you can use the Patch function to modify or create a record in datasource. If you are unaware of the Patch function in canvas app, I suggest to go through the Microsoft Docs link.

Advertisements

However the situation I am going to explain here is bit different. The situation was more of like this.

“There is a contact form spanning multiple screens. The user would enter all the details of the contact including the email address. Depending on the value of email address, an insert or an updated would be performed using the patch operation”.

Advertisements

If I analyze the requirement, basically I would require check if there is any existing contact with the same email address. If exists then I should update, otherwise I should create. Pretty simple huh? Yes it is simple. But specific example is missing in docs. Hence penning this blog in case it is helpful for someone.

For this example:

Datasource – Contacts table of CDS. However this logic can be applied to any data source.

I have kept a really simple single screen here. Mind you I haven’t used a Edit form or a create form. The real requirement was in-fact spanning multiple screens for collecting contact info but for this example I have kept it simple.

Advertisements

Below is the screenshot of the same. A very simple one indeed.

image

Once the button “Update to CRM” is clicked, the magic should happen. To meet the requirement, I use the below formula in the “On Select” property of the button.

image

Formula:

Patch(Contacts, {contactid : LookUp(Contacts, emailaddress1 = EmailText.Text).Contact}, {firstname: FirstName.Text, lastname: LastName.Text, address1_city: City.Text, emailaddress1: EmailText.Text, address1_stateorprovince: ContactState.Text});

If you observe the above formula carefully, I am using the LookUp function to search for a contact with a emailaddress and then getting the contact id. If there is no matching email, contactid would be blank and hence the record is created.

Advertisements

For matching contact it is updated.

Now the question arises – What if there are multiple records which match the criteria? In that case the LookUp function would return a reference to just one of them and the returned record would be updated.

Hope this helps!

Debajit Dutta

(Dynamics MVP)

For consultation/ corporate training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com

Our product offerings:

Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)

CRM-Sharepoint Attachment uploader and metadata manager (http://www.xrmforyou.com/sharepoint-integrator.html)

Record Cloner for Dynamics 365 (http://www.xrmforyou.com/record-cloner.html)

Delegation in canvas apps power apps. know about it before you start working with large datasets.

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 is certainly changing a customer’s view point on mobile rollout feasibility for their business. However more often than not, we as consultants come across customers having significant data in the system. And while we don’t think much about data volumes while dealing with model driven apps, the same cannot be said about canvas apps.

And why is that so? The reason is because of “Delegation”. A very detailed explanation of the delegation feature is explained in this docs link. However let’s see from the implementation perspective how does it affect the canvas app you build.

Advertisements

So the first question is – “What is delegation?”. Usually when we hear the term delegation, we think of something related to user access like delegate privileges and stuff. But delegation in canvas app is related to fetching of data from data sources.

Well canvas app have some really formulas built in to query and filter data sources, very much excel like. So what happens when you put a query similar to the one below in Canvas apps.

image

If you track the request in Fiddler, this is what you get

Advertisements

/api/data/v9.0/accounts?$filter=(name eq ‘Test’)&$select=accountid,name

As you can see canvas app delegates the query to data source and gets the results back. Kind of obvious right? After all if there are thousands of records in the system it would be extremely bad design to bring in all the records to client and then apply the filter.

But there are some situations where canvas apps need to do just that. And why is that so? As I have mentioned earlier since canvas apps supports excel like formula, not all filters can be applied directly to data source as that might not be supported. Let’s take an example where I want to show the average of the credit limit for all my accounts. Below is the formula for the same.

image

The moment I write this formula, I get a blue line below it and then get a delegation warning that it might not work correctly on large data sets. The reason is the formula cannot be delegate to data source.

Advertisements

Now the question arises – “Does Canvas app bring all the records on the client side and try to take the average?”. Well the answer is No. For performance benefit, canvas app will bring in only the first 500 records no matter how much data you have in the table. Even the 501th record would not be considered for average calculation in my query. Hence the average value may not reflect the correct value.

Trust me this have happened so many times with me where I received the complaint that data shown is not being correct.

Advertisements

Is this 500 limit set somewhere or is it hardcoded in the framework? Well it’s configurable till a maximum value of 2000.

To change this limit, go to File menu of your canvas app and then Settings –> Advanced settings –> Data row limit for non-delegable queries

image

So keep in mind this delegation stuff next time you query with large data sets.

Hope this helps!

Debajit Dutta

(Dynamics MVP)

For consultation/ corporate training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com

Our product offerings:

Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)

CRM-Sharepoint Attachment uploader and metadata manager (http://www.xrmforyou.com/sharepoint-integrator.html)

Record Cloner for Dynamics 365 (http://www.xrmforyou.com/record-cloner.html)

create controls dynamically in Canvas App power apps using galleries

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

Before I even go ahead and add more on this. Spoiler alert!  This blog is not going to introduce you to a new API which allows you to add/ remove controls dynamically in a canvas app. As of the time of writing this blog, there is no API in canvas app to accomplish this feature similar to controls.Add() or controls.Remove() feature in ASP.NET.

Before I even go ahead and add more on this. Spoiler alert!  This blog is not going to introduce you to a new API which allows you to add/ remove controls dynamically in a canvas app. As of the time of writing this blog, there is no API in canvas app to accomplish this feature similar to controls.Add() or controls.Remove() feature in ASP.NET.

Advertisements

Here I am going to discuss about a workaround that I recently implemented for a customer having similar requirement.

Long story short, the customer had a requirement like this –

  • On a canvas screen, there is a button to get the add checklists for a record. The number of checklists are dynamic and depends on user selection of other parameters.
  • Checklists can be of type textbox where the user can enter data manually or of type checkbox
  • one checklist of type text and the other of type checkbox are shown by default to the user
  • The user can add as many checklists they want and the instructions for each checklist is dynamic as well.
Advertisements

So let’s see how we can set-up a quick POC for this.

First I go ahead and create a new blank app.

Then I go ahead and insert a vertical gallery control. I rename the gallery to “ControlsGallery”.

image
image

I delete all the contents of the gallery and insert three controls.

  • Label  – To show dynamic instructions
  • Text Input – For text input checklist.
  • Checkbox – For checkbox checklist.
Advertisements

Also added button to add or remove checklist.

image

Our next task was to populate the Items of the controls gallery. But we had a requirement that by default couple of checklists should be shown to the user.

Advertisements

We use the App OnStart event to declare the collection.

image
ClearCollect(DynamicControls, {Type:"Textbox", Value:"", Instruction: "Default Checklist 1"}, {Type:"Checkbox", Value: "", Instruction: "Default Checklist 2"});

What we are doing here? We are basically creating a collection called “DynamicControls”. And in the collection we are inserting two items. Each item has three properties.

  • Type – To determine the type of checklist
  • Value – The value input of the checklist control
  • Instruction – The label to show for the checklist.

The next step is to set the Items collection of the Gallery to this DynamicControls collection.

image

Once the Items property is set, it’s now time to bind our control elements in the gallery to the corresponding properties of the collection. Below are the bindings of each.

Advertisements

1. Instruction Label binding

image

2. Textbox Binding

First we bind the “Default” property of the textbox to the value property of the Collection.

image

Then we bind the visible property to the below formula as shown in the screenshot.

image

3.  Checkbox binding

Bindings are similar to the Textbox input. Check for below screenshots.

image
image

We are all set with the bindings. I created some extra stuffs to actually add instructions at runtime using Add Checklist button. Below is the entire stuff in action.

Advertisements

I hope this helps!

Debajit Dutta

(Dynamics MVP)

For consultation/ corporate training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com

Our product offerings:

Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)

CRM-Sharepoint Attachment uploader and metadata manager (http://www.xrmforyou.com/sharepoint-integrator.html)

Record Cloner for Dynamics 365 (http://www.xrmforyou.com/record-cloner.html)

Configure Customer lookup in canvas apps to show either contacts or accounts

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

Happy new year to all my blog readers and this is my first blog of 2020. And how about starting with a simple one and that too on canvas apps!

So this was my customer requirement. They were designing a canvas app for their business users which was basically kind of contact management. And while designing the contact edit form, they needed to show a form similar to the below one.

Advertisements
image

important fields to consider in the above screenshot are “Parent entity” & “Is company contact”.

Parent Entity field is nothing but the Company name (parentcustomerid) field of the contact. “Is Company Contact” is a custom field of type boolean.

In short the requirement was if that if the contact is a company contact, then the Parent entity field should allow users only to select Accounts else it should allow users to select only contacts. We will basically accomplish the following.

Advertisements
  • Show account/ contact dynamically depending on business logic
  • While switching between accounts and contacts dynamically, you may face the issue where either for contact or account, the display text does not show up. We are going to resolve that too.

So we set the Items property of the combobox with the below formula.

If(IsCompanyContact.Value = true,[@Accounts].’Account Name’,[@Contacts].’Full Name’)

image

If you are not aware of [@Accounts] or [@Contacts] syntax, refer to the Microsoft Docs link to learn more about record references.

Advertisements

So far so good. So we run the application.

image

So when “Is Company Contact” is selected, Parent Entity shows up the accounts as expected (screenshot above). Trust me, that’s the easy part. The one that will throw you off is the next one.

Advertisements

When the checkbox is unchecked, it should be showing the contacts. But below is how it shows up. Basically the contacts are loading but they are showing blank without any attribute value although we have specified fullname of the contact to show up in our formula.

image

We missed a simple thing and trust me it can consume some precious time of your day. The trick is to set the “Display Fields” property of the combo box. By default it was set to name for us and that’s the reason why account was showing us.

Advertisements
image

We changed that to the below formula. And now it showed up fine.

If(IsCompanyContact.Value = true,[“name”],[“fullname”])

image

Hope this helps!

Debajit Dutta

(Dynamics MVP)

For consultation/ corporate training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com

Our product offerings:

Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)

CRM-Sharepoint Attachment uploader and metadata manager (http://www.xrmforyou.com/sharepoint-integrator.html)

Record Cloner for Dynamics 365 (http://www.xrmforyou.com/record-cloner.html)