Wednesday, September 5, 2012

How to open CRM FORMS and Web Resources correctly!?


Some CRM implementations require the use of custom Jscript to pop open a new entity form window or a window displaying an existing record in CRM. Previously, there was no “supported” way to do this, since we had to use the window.open Jscript object which relies on the use of the Document Object Model (DOM).

Update rollup 8 provides new SDK functions which CRM configurators can use to open CRM forms and web resources in a nice supported way.

The Old Way - Making the URL static with parameters:
Here is an example of how to pop open an existing Account using Jscript:

function popAccount() {
var accountId = "8FB2CCE4-20E4-E111-9700-00155D042F0D";
var url = Xrm.Page.context.getServerUrl() + "/main.aspx?etn=account&id=" + accountId + "&pagetype=entityrecord";
window.open(url);
}

Here is an example of how to pop open an HTML Web Resource using Jscript:

function popHTML() {
var url = Xrm.Page.context.getServerUrl() + "//WebResources/iaf_/html/test.html";
window.open(url);
}

Although these methods do work, they could potentially break as new rollups are applied to your system, or when CRM 2011 is available on multiple browsers.

The New way - New functions :)

function popAccount() {
var accountId = "8FB2CCE4-20E4-E111-9700-00155D042F0D";
Xrm.Utility.openEntityForm("account", accountId);
}

If we wanted to pop open a new Account form, we can exclude the ID parameter.
Here is an example of how to pop open an HTML Web Resource using Jscript:

function popWebResource() {
var webResourceName = "iaf_/html/test.html";
Xrm.Utility.openWebResource(webResourceName);
}

Please note this is only a few of New functions released in rollup 8 related to "Xrm.Utility"  :)

Happy Xrm'ing!

Source: http://blogs.msdn.com/b/crm/archive/2012/07/18/new-xrm-utility-functions-in-update-rollup-8-for-microsoft-dynamics-crm-2011-and-microsoft-dynamics-crm-online.aspx