Kids, don't try this at home!

Tips & Tricks for C#, ASP.NET and CRM

July 2009 - Posts

Dynamics CRM - Programmatically Block Outbound Emails

Time for another crm goodie...

We've been working on a little project that needed blocking of certain outbound emails, with the Dynamics CRM plugin architecture this made it very very simple. For whatever reason, if you want to block outbound emails from Dynamics CRM programmatically, hook into the Send message on the email entity at the Pre stage synchronously then set the IssueSend property to false.

A bit of code
if (context.MessageName.Equals("Send", StringComparison.InvariantCultureIgnoreCase))
{
    context.InputParameters["IssueSend"] = false;
}

A little gotcha, the system marks the email as Sent even though we've blocked it, so be careful with that one. Hopefully this is useful to someone else. We've used this technique to write a neat little addon for Dynamics CRM, keep an eye out for it!

Posted: Jul 21 2009, 06:37 PM by gperera | with no comments
Filed under:
Dynamics CRM 4 Mobile Express Released!
Mobile Express for Dynamics CRM is now available for free from Microsoft. You can download it from http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=f592ec6c-f412-4fd5-9a80-cd3bcbd26d8b

Here it is running on the iPhone

Main Accounts
Active Accounts New Account
Dynamics CRM - Backup, Restore & Publish Customizations Programmatically

Here is a simple class you can use to backup, restore and publish dynamics crm customizations programmatically. Please keep in mind that dynamics crm customizations are additive, which means, if you import a set of customizations lets say a new attribute on the account entity and you restore a backup of the old customizations the new attribute on the account entity that was imported will not be deleted.

Usage
CrmCustomizations customizations = new CrmCustomizations(service);

You can backup to an xml file or a zip file by calling the Backup method. Backup method takes care of creating the xml or zip file by looking at the output file extension.
    bool backedup = customizations.Backup(@".\customizations_backup.xml");
    // or to a zip file
    backedup = customizations.Backup(@".\customizations_backup.zip");

To restore a backup call the Restore method. You can pass it a .zip file or a .xml file path.
    bool restored = customizations.Restore(@".\customizations.xml");

Once you have restored you need to publish the customizations, to publish call the Publish method. It will publish all customizations.
    bool published = customizations.Publish();

Download the class file

Enjoy!

Posted: Jul 10 2009, 01:34 PM by gperera | with 3 comment(s)
Filed under:
Dynamics CRM - Synchronize with Xero Accounting Software

Here is a sneak preview of Dynamics CRM integrated with Xero that we have just completed. Yesterdays post (automatically emailing pdf invoices) is part of this whole system we've been working on. If you are using Xero as your accounting software it can now be integrated seemlessly into Dynamics CRM.

Dynamics CRM to Xero 
   Take a look at this 5 minute video (audio coming soon...)

What Can It Do?


In real-time

  • Synchronize accounts in Dynamics CRM to and from Xero
  • Synchronize invoices from Dynamics CRM to Xero
  • Synchronize invoice payments from Xero to Dynamics CRM
  • Synchronize account codes from Xero to Dynamics CRM

It has been a pleasure working with the Xero API, Xero has done a very nice job. Looking forward to v2 which will provide the ability to synchronize credit notes, currency, additional payment options and more...

Thanks to Tony Rule from Xero for guiding us through the API and Amanda Mattson from XrmLinq for the LINQ to Dynamics CRM tool.

Posted: Jul 03 2009, 12:49 PM by gperera | with 1 comment(s) |
Filed under:
Dynamics CRM Workflow - Automatically Email any Report generated in CRM as a PDF attachment

Time for another Dynamics CRM goodie...

Send an invoice to a customer with a pdf attached using a dynamics crm workflow

We try to automate as many things as we can, automatically sending invoices is one of them. Workflow as you know in Dynamics CRM is very powerful, specially the ability to create custom activities and hook into the pipeline. We took advantage of this, we created a custom workflow activity that takes in any entity, Email and a Report, automatically turn it into a PDF, attach it to the email and send the email.

Take a look at this 5 minute video to see how it works. If you're interested in using this in your organization contact me via this link.

Under The Hood


Report2Pdf
This class does the heavy lifting, it has a method called Download, connects to the report server, configures the parameters and renders the report as a PDF then returns a byte array.

public
class Report2Pdf
{
    public static byte[] Download(string rsUrl, string rseUrl, 
        System.Net.NetworkCredential credentials, string report, 
        Report2PdfParameter[] inputParameters, string culture)
    {


Workflow Activity
Straight forward, read the configuration data, makes a call to the Report2Pdf.Download method, creates an activitymimeattachment then executes a SendEmailRequest.

byte[] data = Report2Pdf.Download(config.Url, config.ExecutionUrl,
    new NetworkCredential(config.UserName, config.Password, config.Domain),
    report.Location, rps.ToArray(), config.Culture);


LINQ and Dynamics CRM
Thanks to Amanda and the team at XrmLinq for giving us access to their library. This has made data access so much easier. Something that would take atleast 10-20 lines of code and a lot of effort messing around with FetchXml has now been reduced to 3 lines and LINQ!

var
config = (from c in xrm.ReportServerConfigurations
              where c.ReportServerConfigurationId == report.ConfigurationId
              select c).SingleOrDefault();

Posted: Jul 02 2009, 04:43 PM by gperera | with 4 comment(s) |
Filed under: , ,
More Posts