Wednesday, January 30, 2013

Supported ways of accessing URL addressable Forms/Reports Scripts.

While using CRM there may be conditions in which user wants to open forms and reports programmatically. For this we can write the scripts which will open the forms and reports.
Open CRM forms using script:
The form can be open using openEntityForm(); method.
          Syntax :  Xrm.Utility.openEntityForm(name,id,parameter);
Parameters :
Ø  name: (Required ) The logical name of an entity.
Ø  id: (Optional) The string representation of a unique identifier or the record to open in the form. If not set, a form to create a new record is opened.
Ø  parameters: (Optional) A dictionary object that passes extra query string parameters to the form. Invalid query string parameters will cause an error.
1.     To Open Blank new entity record :
2.     To Open Existing CRM Form :
3.  To open Form with default value set using parameter  
function OpenNewContact() {
 var parameters = {};
//Set the first name of contact to “Scott”
parameters["firstname"] = "Scott";
 //Set text in the Description field.
 parameters["description"] = "Description  for this record";
//Set the Parent Customer field value to “John”.
 parameters["parentcustomerid"] = "2E862A5A-7D0F-E211-8090-00155D000501";
 parameters["parentcustomeridname"] = " John ";
 parameters["parentcustomeridtype"] = "account";
 //Set Do not allow phone to "Do Not Allow".
 parameters["donotphone"] = "1";
 // Open the window.
 Xrm.Utility.openEntityForm("contact", null, parameters);
Open Report using script:
We can also run the report using script. We just have to pass the url to; method. Below example shows how to open the report.
Syntax :;
url need the following parameters:
Ø  action: Two possible values for this parameter are run or filter.
·         When run is used, the report will be displayed using the default filters.
·         When filter is used, the report will display a filter that the user can edit before clicking the Run Report button to view the report.
Ø  helped:(optional) The value should correspond to the report FileName attribute value.
Ø  Id :This parameter is the report ReportId attribute value.
function OpenReport() {
try {
//call function which will return encoded url
var url=getReportURL(filter,AllContacts,'35F560E6-1606-E211-A8FC-00155D000501');;
alert("OpenReport  Error >> "+e.description);
//function to create and encode url
function getReportURL(action,fileName,id) {
   var orgUrl = Xrm.Page.context.getClientUrl();
   var reportUrl = orgUrl +
    "/crmreports/viewer/viewer.aspx?action=" +
    encodeURIComponent(action) +
    "&helpID=" +
    encodeURIComponent(fileName) +
    "&id=%7b" +
    encodeURIComponent(id) +
   return reportUrl;


  1. I am new in CRM :)
    I used openEntityForm() method
    But it gives object reference error
    Am I missing something?
    Please help

  2. You might not be having Update rollup 8 or above installed on your CRM instance.

    OpenEntityForm(); is function of Xrm.Utility and Xrm.Utility object was added in Microsoft Dynamics CRM 2011 Update Rollup 8.

    To use this function you should have at least CRM rollup 8 installed.

    Hope this helps!