Thursday, March 24, 2011

Dynamics 2011 Online - Custom Reports using FetchXML

If looks like FetchXML which went out of favour with CRM 4.0 has made a comeback and you need to use it you want to write a custom report for the online version of Dynamics 2011.  This is because you don’t have direct access to the database and crm's filtered views. 

Microsoft have provided an extension for BIDS (Business Intelligence Development Studio) which allows you to connect to CRM online and write FetchXML based reports. BIDS is a cut down version of Visual Studio with just the reporting writing components installed. You can get the extension from here
Once you install the extension you can use it to create datasets in your report by writing FetchXML. Unfortunately you cannot use it to modify any of the system reports because if you download one of these and open it you will discover it use sql rather than FetchXML.

If you are going to write a report from scratch there are a few things to note. The first is that you need to use an embedded data source in your report not a shared data source otherwise you will get an error when you import the report into CRM.  So add a data source to your report called CRM and add you online url as the connection string. Under credentials select the “Use this user name and password” and enter your live email address and password. 

I have not found a good tool for creating FetchXML that works with CRM 2011 online so one of the easiest things to do is to use advanced find in CRM to create a query and then select the Download Fetch XML option to save it to a local file and cut and paste this into your report query.

Wednesday, March 09, 2011

CRM 2011 - Phone Format Validation using JavaScript and Regex

Reusing JavaScript functions in CRM 4.0 was not easy and many people simply copied the code from one form or field to another so they ended up with lots of duplicated code.

Dynamics CRM 2011 introduced the concept of web resources which are files of reusable resources. In this example I am going to create a JavaScript library as a web resource file to hold a function which validates the format of a mobile phone number using a regular expression. Under customization create a new resource file of type JavaScript.

Add caption

Click on Text Editor and add the following JavaScript to the source

function validateMobile(context)
var mobi =context.getEventSource().getValue();
mobiRegex = /^(083|084|085|086|087|088|089)\s?\d{3}\s?\d{4,5}$/;
if( !mobi.match( mobiRegex ) )
   event.returnValue = false;
   alert("The format of the mobile no is incorrect") ;

Customize the main form of the Contact entity and click on the Form Properties and add the new resource file we created as a library. It can now be used in the form

Click on the mobile number field to hook up the onChange event to our newly created validation function. Under the event tab add a new event handler as shown. Make sure you check the “Pass execution context as first parameter” so that we can access the field context in the Javascript function. Save the form and publish the Contact entity.

Now on the contact form when the mobile number is changed the validateMobile function will be fired and because we are using a web resource file we can reuse it throughout the solution.

Friday, March 04, 2011

Cash to switch to Dynamics CRM Online

It looks like Microsoft are going after SalesForce customers in a big way. If you switch from a competing CRM product to Dynamics CRM Online you get cash back. More details here