Wednesday, 22 February 2012

Creating a custom report in CRM 2011 by BIDS

Hi,

Long time no post on my blog. Actually, sometimes I wonder whether I should continue this blog anymore or not... No one really care to this one... :D

Anws, still on my way study everything about CRM: javascript, plug-in, silverlight, BI, reporting... A lot of things.. And till now I'm quite happy with what I studied. At least I began knowing what can do with CRM, and how to do that,etc. which are good when you meet the customers :D.

Today, regarding a demand from people on Microsoft CRM forum for knowing how to create a custom report in CRM. Then I decided to wirte this blog to describe step by step how to achieve this purpose.

Firstly, you need to have the following things in order to create and deployed a report successfully in CRM:
- Business Intelligence Development Studio (BIDS) which run on Visual Studio platform.
- Ensure that your CRM includes Microsoft Dynamics CRM Reporting Extensions.
- Your CRM reporting server URL (which you define when setting up CRM system)

Here is step by step:

- Step 1: Open your BIDS. Remember that BIDS run in VS environment, then you will see the VS screen openned up.


- Step 2: Creating a new Reporting project



- Step 3: In Solution Explorer --> Right Click Report --> Create new report --> you will see the Report Wizrad pop up


- Step 4: Creating a Data Source for your report. Data Source is like a link which connects your report to the database storing your data. In order to define a Data Source, you need to know your Database Server and Database Name:




-Step 5: After defining the Data Source, clicking Next --> Query Builder window will pop up. Here is the place that you build queries to retrieve your data.



-Step 6: Click Query Builder --> Click Add Table icon --> Choose all tables that you need (in this example, I chose Account Table )

 
- Step 7: After adding tables, selecting fields that you want to view in the report. You will see the equivalent query to your select below.


- Step 8: Click Next until the end of the dialog and put name of report inside. Now you have a report interface like that:


The left hand-side is all things included in your report. You could see "Name","Address".. fields in the report content.

- Step 9: Now, if you want to add some more parameters to filter your report result. You could go to "Parameter"  --> Add New


- Put available values for the parameter. Here I would like to put the "Account Name" field



- Step 10:  Now the report is nearly done. Then you "Build" the report.
                 After that, need to Deploy the report into your CRM Reporting Server. To do so, open Properties, add "TargetReportServer" by your Reporting Server URL:



- Step 11: Go to your CRM --> Workplace --> Report --> Add new report --> Add existing report --> put the "RDL" file in your report project into the CRM



- Step 12: Testing your report by opening it ! Here you will see the filter condition which is "Account Name" we created before and the result when running report.



Please feel free leave your comment if you dont understand any step. :D. And Please comment a bit if you find this blog is useful :P. Many thanksssss

Thursday, 9 February 2012

Create,Update,Retrieve, RetrieveMultiple Records in CRM 2011 with Javascript REST endpoint

Hi,

For who are new with Microsoft CRM 2011, this is a first lession that you should know: How to create, update, retrieve and delete a record of an entity in CRM by using javascript. These basic operations help you a lot in developing your CRM by using the client-side language Javascript.

There are two ways to achieve the results:
1. Using directly the REST Endpoint method like in SDK sample in this link: http://msdn.microsoft.com/en-us/library/gg334427.aspx --> for me, this way is complicated, because you have to bring the whole REST Endpoint function to your code, which makes your code like a mess.

2. Download the REST Endpoint method from SDK  and use it like a library for your javascript code.

Now are steps how to do the second way:

- Step 1: Prepare the following required js:
       + JavascriptRESTDataOperations --> from SDK: SampleCode\JS\RESTEnpoint\JavascriptRESTDataOperations
       + jquery1.7.1.js --> from http://jquery.com/
       + json2.js --> from http://www.json.org/json2.js

- Step 2: Creating your javascript as following:

//Create record
function Create_CRMObject()
{ var CRMObject = new Object();
  CRMObject.Id = "";
  //createRecord function is in jsoperation.js
  createRecord(CRMObject,"your entity set name", createCRMObjectCompleted,errorCreate) 
  // entity set name, for example: AccountSet, ContactSet, etc
}
createCRMObjectCompleted = function (data, textStatus, XmlHttpRequest)
{ var newCRMObjectCreated = data["d"];  
}
errorCreate = function (XMLHttpRequest, textStatus, errorThrown) 
{ alert("Error");
}

//Update record
function Update_CRMObject()
{ 
    new CRMObject = new Object();
 var CRMObject_Id = "put the GUID here";
 var CRMObject."Attribute" = "put any attribute value here"
 //updateRecord function is in jsoperation.js
 updateRecord(CRMObject_Id,CRMObject,"you entity set name", updateCRMObjectCompleted,errorUpdate); // entity set name, for example: AccountSet, ContactSet, etc
}
updateCRMObjectCompleted = function (data, textStatus, XmlHttpRequest)
{ alert("your update is successful");  
}
errorUpdate = function (XMLHttpRequest, textStatus, errorThrown) 
{ alert("Error");
}

//Delete Record
function Delete_CRMObject()
{  var CRMObject_Id =" put the GUID here");
   //deleteRecord function is in jsoperation.js
   deleteRecord(CRMObject_Id,"your entity set name", deleteCRMObjectCompleted, errorDelete);   
}
deleteCRMObjectCompleted = function (data, textStatus, XmlHttpRequest)
{}
errorDelete = function (XMLHttpRequest, textStatus, errorThrown) 
{ alert("Error");
}

//Retrieve Record
function retrieve_CRMObject()
{ //retrieveRecord function is in jsoperation.js
   retrieveRecord("put your record GUID here","put your entity set name", retrieveCRMObjectCompleted, errorRetrieve);
// entity set name, for example: AccountSet, ContactSet, etc
}
retrieveCRMObjectCompleted = function (data, textStatus, XmlHttpRequest)
{ var newCRMObjectRetrieve = data["d"];
  //now you could retrieve any field belongs to your record
}
errorRetrieve = function (data, textStatus, XmlHttpRequest) 
{ alert("Error"); 
}

//Retrieve Multiple Records
function retrievemultiple_CRMObject() 
{  retrieveMultiple("your entity set name","", retrievemultipleCRMObjectCompleted, errorRetrieveMultiple);
// entity set name, for example: AccountSet, ContactSet, etc
}
retrievemultipleCRMObjectCompleted = function (data, textStatus, XmlHttpRequest)
{ var CRMObject = data;
  if (CRMObject.length !==0)
   { for (i=0, i<CRMObject.length, i++)
      { CRMObject[0].id = ... //retrieve any field you want
   }   
   }
  else
  { alert("no record");
  }
}
errorRetrieveMultiple = function (data, textStatus, XmlHttpRequest) 
{ alert("Error"); 
}

Save all of above code in CRMObject.js

- Step 3: Add all 4 above js files in your entity's form. Put the function name for onload or onsave event. Then you could do anything you want now !

I hope it helps. Please email to linhhk87@gmail.com if you have any further question to implement it !




    

       

Wednesday, 1 February 2012

Using window.showModalDialog in IE9 - CRM Customization

Hi everyone ( I hope someone takes a look at this blog really..),

Here is a very small tip for you guys to control how your window dialog appear in CRM.

The scenario here is you would like to create a new button in CRM ribbon. When you click the button, a window dialog will be pop up.

 The solution is writing a javascript function to show up the window dialog using window.showModalDialog method. All about this method could be found in this link: http://msdn.microsoft.com/en-us/library/ie/ms536759(v=vs.85).aspx

However, your window dialog appeareance depends on kind of browser you use (IE, Firefox, Chrome, etc..). Now i'm using IE9, then figure out one problem with it.

As you see the following javascript:

 window.showModalDialog(url, null, "dialogHeight:600px;dialogWidth:800px;center:yes; resizable:1;maximize:1;minimize:1;status:no;scroll:no" );

In IE9, all the features defined in the javascript above (underlined) could not be fired. Then you have to enbale the Compatibility View in IE9 in order to run it correctly.

To enable Compatibility View in IE9, the following steps:
- Alt + T to see the toolbars
- Go to Tools tab, you will see Compatibility View Setting


 - Then adding your website (here is your CRM) and select Display all website as shown in the below pic



So now, run your javascript again and see your window dialog appear correctly as your code !

I hope it'll be useful.