Friday, March 20, 2015

CRM 2015 Client API Cheat Sheet

I was recently digging through the MSDN pages for CRM client-side programming and remembered that there was a cheat sheet for CRM 2013 (thanks Rami Mounla). There have been vast improvements in the client-side API, so I decided to update the cheat sheet. This is a very expansive version of the cheat sheet. I have included all methods (to my knowledge), their description, and their parameters.

Plus, I scaled it up to 18x24 to fit on a couple of posters that I had printed for my office.


18in x 24in: PDF and Powerpoint

I would be happy to upload additional sizes if anyone would like to create them.

This has also been posted on CRMUG.

Wednesday, February 25, 2015

CRM 2015 Xrm.Page.context has null values

Recently I stumbled across an issue with an On-Premise, IFD deployment of CRM 2015. The issue involved the Xrm.Page.context not being completely populated when being used on an HTML web resource. Upon further investigation I found that a strange redirect was occurring with CRM 2015 when loading the ClientGlobalContext.js.aspx as a script in the HTML header.
In previous versions of CRM, adding the script tag to load ClientGlobalContext.js.aspx was straight forward and would load the context with out issue. However, in CRM 2015, you will see that the same ClientGlobalContext.js.aspx is loaded, then another one gets requested.  
As you can see in the picture above, the second request receives a 404 because the URL contains the organization name and is not formatted correctly for IFD deployments.
If we dive deeper we can see what is happening in the first call:
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: text/javascript; charset=utf-8
Expires: -1
Vary: Accept-Encoding
Server: Microsoft-IIS/8.5
X-AspNet-Version: 4.0.30319
REQ_ID: 190d26df-27ea-4383-a166-0b3c2af636c5
X-Powered-By: ASP.NET
Date: Wed, 25 Feb 2015 19:32:42 GMT
Content-Length: 822

document.write('<script type="text/javascript" src="'+'\x2f_common\x2fglobal.ashx\x3fver\x3d698467308'+'"></'+'script>')
document.write('<script type="text/javascript" src="'+'\x2f_common\x2fwindowinformation\x2fwindowinformation.js.aspx\x3flcid\x3d1033\x26amp\x3bver\x3d698467308'+'"></'+'script>')
document.write('<script type="text/javascript" src="'+'\x2f_common\x2fentityproperties\x2fentitypropertiesutil.js.aspx\x3ftstamp\x3d1469436481\x26amp\x3bver\x3d698467308'+'"></'+'script>')
function GetGlobalContext(){return Xrm.Page.context};var xhr = new XMLHttpRequest();
xhr.open("GET", "/<OrgName>/WebResources/ClientGlobalContext.js.aspx", false);
xhr.addEventListener('load',function(){if(xhr.status == 200){eval(xhr.responseText);}});
xhr.setRequestHeader("Content-Type", "application/json");xhr.send();
As you can see the highlighted line is the cause of the problem. The ClientGlobalContext.js.aspx that we are used to using is now attempting to redirect to a different ClientGlobalContext.js.aspx that loads up all of the goodies that we are used to (getUserID, getOrgName, etc).

According to this thread, Microsoft is already aware of the problem and intends on fixing it in UR1 (Release date: TBD). Unfortunately, there may be some users already experiencing this issue in production environments. For those users, I would suggest using the workaround provided by Yona Low in the same thread. I will quote it below:
A temporary workaround we implemented is to add a URL Rewrite rule in IIS to remove the org name from the URL, if it exists when requesting ClientGlobalContext.js.aspx. The rule needs to be added before the built-in CRM rules.
Hopefully this will be fixed in the next UR.
Here are the values used:
Pattern: /?([0-9a-zA-Z][^/]*)?/?((?:%7b|\{)[^/]*(?:%7d|\}))?/?WebResources/ClientGlobalContext.js.aspx
Condition: {R:1} matches .+
Action: Rewrite to /WebResources/ClientGlobalContext.js.aspx
The above URL Rewrite rule will only work for IFD-only deployments. It has not been tested and will probably not work for mixed deployments.
Here is a screenshot of the settings:
I have implemented this workaround successfully, and I hope that it will also help you. Please follow the Microsoft Connect Feedback item related to this bug, and possibly comment on it as well.

This has also been posted on CRMUG.

Monday, December 15, 2014

CRM 2015 TypeScript Definition

Hello everyone, and welcome to my blog!

I just finished uploading the CRM 2015 type definitions to NuGet under the name xrm-2015.TypeScript.DefinitelyTyped. I have also put in a pull request to the DefinitelyTyped repository on GitHub.

I will be working on the 2011 and 2013 definitions, and I hope to have them up on NuGet and GitHub in the coming days.