CRM 2013 – Let XRM.Utility.OpenEntityForm open CRM forms for you

I wrote a blog post about creating a creating a new record with Javascript and then opening this new record by dynamically creating a url and then some problems I had with that and whilst reading about my trials and tribulations with JavaScript and bugs,  Brian Bayes sat me down (virtually), gave me a cup a tea and said “Hosk, stop all this hurrying and scurrying around, creating dynamic urls, why don’t you just use my good buddy Xrm.Utility.openEntityForm to do all that tricky stuff” and then gave me one simple line to do the method I had written.

Brian didn’t actually use those words but left me  a comment in linkedin saying this function would have have help but that wouldn’t have been as amusing.

So I looked into Brian’s suggetion and by gum he was right.

http://msdn.microsoft.com/en-us/library/72a66f93-92df-42b9-a8fd-b6125c7fe83b#BKMK_OpenEntityForm

Initially I thought it was only available in CRM 2013 but they snuck it in during CRM 2011 rollup 8, which shows you the benefit of reading what useful things are in the rollups.

Xrm.Utility.openEntityForm(“account”,GUID)

http://msdn.microsoft.com/en-us/library/72a66f93-92df-42b9-a8fd-b6125c7fe83b#BKMK_OpenEntityForm

You can also pass in parameters you want to set on the form

var parameters = {};
parameters["formid"] = "b053a39a-041a-4356-acef-ddf00182762b";
parameters["name"] = "Test";
parameters["telephone1"] = "(425) 555-1234";
Xrm.Utility.openEntityForm("account", null, parameters);

The Xrm.Utility object provides a container for useful functions not directly related to the current page. This object was added in Microsoft Dynamics CRM 2011 Update Rollup 8.

var newWindow = Xrm.Utility.openEntityForm("contact");
newWindow.moveTo(0,0);
newWindow.resizeTo(800,600);
  • e helped you here?47m ago
  • Ben HoskingBen Hosking Everyday is a school day. Although the project I was working on was CRM 2011 so I’m not sure that would have worked.44m ago

  • Brian BayesBrian Bayes Ah I see, Xrm.Utility has been tucked away since CRM 2011 Rollup 8 and I only discovered it a couple of months ago to be honest.32m ago

  • Ben HoskingBen Hosking knowing that would have saved me at least an hour mucking about with the bug and getting the url correct. Great comment, cheers.