URL Encoding in CRM 2011 Views – Bug and Workaround / Fix

In our internal CRM org that is used for customer service, I developed a custom entity called Case Cloud Attachments to use to compile all attachments for a case into one centralized place.  Those attachments could have been done from CRM, uploaded through our portal, or sent in to a related email on a case.

In this custom entity record, there is a single line of text field with URL format.  This URL would point to the file that was uploaded to Azure blob storage.  This record is then related to a parent case so while reviewing the case you could see all attachments in one place.

 


Notice that as you mouse over the link, the URL is messed up and an http:// has been pre-pended to URL.

When we were using Update Rollup 11 (UR 11) in our CRM on premise deployment, this URL would still work, even though the display of the URL in the view showed incorrectly.

All was well and nobody noticed…until I upgraded to Update Rollup 13 (UR 13) this past week.  Suddenly, it stopped working, and if you clicked the link in a View, it would try to load the bad URL… and of course it failed.

One interesting note: If you open the full record and click the URL text field on the main record form, the link would open just fine in UR 13.  It only failed to open if you clicked it in the view.

The Workaround / Fix:

It turns out that this is a bug in CRM views, and a bug in the way I was writing text to that field.

Because many of the email attachments that were coming in to cases were in-line images embedded in the email, they don’t have an actual file name.  So the Email system assigns it a random name and number like image001.png, image002.jpg, etc.

At the same time it also wraps this name in Braces { }.  That turned out to be the problem, because a URL should not have braces in it.  They need to be URL encoded to:

%7b – open brace {

%7d – close brace }

For some reason UR11, probably because it was IE specific browser only, was able to translate these to the appropriate URL encoding and open the URL.  Since I am sure that the JS code for views had to be modified in UR 12 and also UR 13 to support multiple browsers, suddenly the URLs were no longer being translated correctly.

I modified my plugin to use the .Net function HttpUtility.UrlEncode to properly encode the URL before I write the record, and that fixed it.

It’s still a bug in the way views work in CRM grids, but at least I have a way to prevent it in the first place.  I opened a support case with Microsoft and was able to reproduce this problem with them, even on a standard entity like Account.  They are reviewing it to see if it can be fixed in a future rollup.

Enjoy!

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Do some math and prove your not a robot... *