Do you have the following requirements for your canvas apps?
- You are using the form control in your canvas app and you want to make a field mandatory/ non-mandatory depending on business logic
- You are not using a form. However you have some input controls which should be made required depending on business logic.
If you are having a requirement like this, trust me you are not alone here. And in-fact this is such a common requirement. Here also there can be couple of scenarios. I am going to cover both of them in this blog.
Option 1 – Make a field on the form control as required.
Well, this one is easy. You don’t have much to do here. Here is a simple example where I am displaying the account details of CDS on an Edit form in Canvas apps.
And we have simple example here. We have this Approved field here. For any account which is approved, it is mandatory to put Main Phone details. For that first we select the Main Phone data card and then unlock it.
Once done, selected the “Required” property of the Data card and then set it’s value to value of the Approved checkbox.
And that’s it. When I check Approved, the Main phone is marked mandatory else not
Now that the Data card has been marked mandatory, the form submit is automatically taken care of. When I try to save the account details, I get the below error.
Option 2 – Make an input control required which is not inside form control.
Things are little more complex here since the field is not part of form control and also you have to handle your submit event here. Below is a sample account creation screen where I am not using any form control.
In the OnSelect of Tick icon, I am using the below code to create an account.
Here for every field, you need to create your own logic. For example – for Main phone, I have kept a error label. Below is the formula for the visible property of the label.
This is way to show the notification for the field. But remember we need to stop the save event as well. So for that you need to modify the OnSelect to check for the validity for all fields.
Hope this helped!
You will also like the below posts
Debajit Dutta
Business Solutions MVP
Discover more from Debajit's Power Apps & Dynamics 365 Blog
Subscribe to get the latest posts sent to your email.