Thursday, June 30, 2011

Sending report as pdf in email

Microsoft dynamics crm 2011 on premise only solution. (It's not possible to get to the reporting services web services in the online environment).
1) Get the report from the ssrs web service in pdf format
2) Create email from email template
3) Create the attachment
4) Send the email

I had to do it generic enough that the customer could do it with any report he would like. so I've exported some of the guidelines to xml file, created console application which can be run with windows task scheduler.
It can be found here:
http://emailreport.codeplex.com/

Download link:
http://emailreport.codeplex.com/releases/view/69298

Another option is using the ssrs.
Setup reporting service SMTP and try this solution:
http://community.dynamics.com/product/crm/crmtechnical/b/crmpowerobjects/archive/2011/06/29/report-scheduling-and-email-subscription-in-crm-2011.aspx

Wednesday, June 29, 2011

Creating new report running on specific record

When creating reports in Microsoft Dynamics Crm 2011 Using fetchMXL is required.
Creating reports with fetchXML could make life easier, Like when creating *contextual reports. It can be done by adding enableprefiltering="true"  attribute to entity tag.

Example:

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
<entity name="invoice" enableprefiltering="true">
<attribute name="name" />
<attribute name="customerid" />
<attribute name="totalamount" />
<attribute name="invoiceid" />
<order attribute="name" descending="false" />
</entity>
</fetch>




*Running report on specific record and not on all the record, like in quote report.

Saturday, June 4, 2011

Dynamics crm 2011 javascript and crmrestkit

Dynamics crm 2011 javascript and crmrestkit
I find crmrestkit the easiest and fastest way to work with rest service in Microsoft Dynamics crm 2011. It's really simple, straight forward and supports both synchronous and asynchronous service calls.
In order to get started you should get:

Add them to your Microsoft Dynamics crm 2011 Web resources:

Last step is to add them to the CRM form.
Now everything is ready for using the crmrestkit.
Few samples:
1) Retrieve multiple - synchronous :
var columns = ['new_attributeId', 'new_attributeName'];
var filter = "new_attributeName eq 'WOW'";
var collection = CrmRestKit.RetrieveMultiple('EntityName', columns, filter);
if (collection != null && collection.results != null && collection.results.length > 0) {
var valId = "{" + collection.results[0].new_attributeId + "}";
var name = collection.results[0].new_attributeName;
var attribute =Xrm.Page.getAttribute("new_attribute1");
attribute.setValue([{ id: valId, name: name, entityType: "EntityName"}]);
}
2) Retrieve multiple – Asynchronous
var columns = ['new_attributeId', 'new_attributeName'];
var filter = "new_attributeName eq 'WOW'";
CrmRestKit.RetrieveMultiple('EntityName', columns, filter,  function (collection) {
if (collection != null && collection.results != null && collection.results.length > 0) {
 var valId = "{" + collection.results[0].new_attributeId + "}";
var name = collection.results[0].new_attributeName;
var attribute =Xrm.Page.getAttribute("new_attribute1");
attribute.setValue([{ id: valId, name: name, entityType: "EntityName"}]);
}
}); 
As you can see it is simple to read, write and understand.
When working with rest services remember that entities and attributes schema names are case sensitive.
In order to get the right name go to:
CRM website->setting->customization->developer resources-> Organization Data Service.
Or just go to SERVER URL/XRMServices/2011/OrganizationData.svc

Here you can find the names of the Entities, For the Attribute name just add the Entity name to the end of the link Example: SERVER URL/XRMServices/2011/OrganizationData.svc/IncidentSet()
In order to see Rest results go to RSS setting in IE and uncheck the "Automatically mark feed …"























Another great way for building the queries without mistakes is using the "Crm 2011 Odata query designer":

http://bingsoft.wordpress.com/2011/03/06/crm-2011-odata-query-designer-crm2011/