Configure redirects in Dynamics 365/ Powerapps portals.

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

Recently I was working in some portal customizations for my client and one of the requirements that came in was to place a re-direct for a portal url. If you are unware of redirects in Portals, this docs link is the perfect place to get started.

To put it short, you can create a redirect URL for an request so that when an incoming request is received for the URL, the user is redirected to a new URL/ page that you have configured.

Advertisements

So the portal developer went ahead and created a redirect url similar to the below one.

image

So basically when the user tries to navigate to the Left Nav Page, the user should be redirected to the Maintenance page. If you want the user to be redirected to an external URL, just fill in the value for Redirect URL field and you should be good. All fields are explained in docs link I shared at the start of this blog.

Advertisements

I have designed a kind of mock here for this blog post. The home page was kind of like below.

image

As it was expected, when the user clicks on the “Left Navigation Page” now, the user should be redirected to the Maintenance page as redirected as per the redirect rule.

Advertisements

However surprisingly enough, the redirection didn’t happen and the user was taken to the usual page configured for that link.

The first impression as it comes along is the redirection is not happening and if this is the first time you are working with redirects, you are bound to get confused.

To understand whether it is happening or not, here is the thumb rule to remember which I could understand purely based on my experience and not something explicitly written – “If the inbound url configured for redirect is already existing, and a web link is referring to the url, the redirect URL for that incoming URL would never fire when the link is clicked and the original page shall still be displayed”.

Advertisements

In this example – the left-nav-page url was still pointing to a valid webpage and hence the redirection never took effect.

So when does redirection really happen. If you are browsing a legacy URL which no longer exist or a webpage link which customer have saved as bookmark but the page url has been modified, redirect URL comes into the picture. If the inbound URL could not be matched with any existing URL’s, redirect rule would start taking effect if a rule is being configured for that inbound request. The Microsoft docs link infact says so – “Customers frequently want to have a simple URL that redirects to a page deeper in the site, or they want to allow for a legacy URL to be used with the site and automatically redirect to a new URL in the site.” But trust me, interpreting this and understanding can be a tough one to start with.

Advertisements

So for this example here, we just changed the URL of the page from “left-nav-page” to “left-nav-page-bak”. Now when we browse the URL – <a href=”https:///left-nav-page”>/left-nav-page”>https://<portalurl>/left-nav-page, we are redirected to the maintenance page as configured in the redirect URL.

Simple one yet tricky. 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)

Display entity image in your webresource in Dynamics 365/ CDS? Use entityimage_url instead of image content.

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 was bit hesitant to write this blog to be honest as I thought it’s pretty mundane and must be quite known to everyone. And we had the same requirement for the customer. They wanted to show the entity image of a contact in a webresource.

Advertisements

The functionality as already implemented and I was just reviewing the code. However when I checked the code, I found there is quite a bit written to show the image.

  • The entityimage field of the account is queried to get the content
  • The whole content is then set using <image src=’data:image/png;base64,<content>’ />

Surprising it is but when I told them there is a better way to do it without querying the content and all, many seemed unware of it. Hence I thought this would be of help to someone faced with similar situation.

Advertisements

For entity image field, there is a separate field created called – “entityimage_url” which can be queried as well. Below is the WebAPI query to get the entity image of an account. Same can be used with any other entity.

https://powerappsforyou2020.crm.dynamics.com/api/data/v9.0/accounts(936B419F-9F4B-E111-BB8D-00155D03A715)?$select=entityimage_url

image
Advertisements

The final step is to set the image url in the src attribute of the image in webresource. And you can see it in your web resource.

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)

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)

Show Consecutive line breaks in alerts in Dynamics 365/ CDS

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

By this time all of us are familiar with Xrm.Navigation.openAlertDialog. What’s more is going to be there in that API. After all it’s an API which just shows some alert.

And yet the simplest of things sometime surprises us. The same experience I had today while dealing with a requirement. It was a simple alert statement where I need to show a  text with couple of consecutive line breaks.

Advertisements

Something like “This is the first line <Line break> <Line Break> This is the second line

Piece of cake right? All we need to do is assign variable with the below code and show it in the alert.

var alertText = “This is the first line. \n \n This is the second line.”;

I was pretty much optimistic that this would work. And this is what it came out.

image

Advertisements

As you can see there is a single break in between the two lines. While we may all have our arguments asking customer to be content with a single line break, it is pretty awkward to tell the customer that a simple thing such as this is not possible to make it work. I was kind of ashamed to say that it is not working. So devoted some more time to it.

A bit of research and then I understood there should be some characters in between two line breaks to make it work. Unfortunately “space” character of keyboard is not working. If you see my text statement, I already have a space in between line breaks.

Advertisements

And then suddenly a eureka moment. How about some invisible characters in between the two line breaks. So I went to the below website and copied some invisible space equivalent characters.

https://beautifuldingbats.com/whitespace/

And it worked. But it is highlight unlikely to continue like this. How about replicating this character in code. So below is what I did.

Advertisements

var alertText = “This is the first line. \n” + decodeURI(“%E2%80%8A”) +”\n This is the second line”;

And this is what we get.

image

Sounded pretty interesting and thought to share.

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)