Attention: We are retiring the ASP.NET Community Blogs. Learn more >

Kids, don't try this at home!

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

  • Dynamics CRM 4 SDK for the iPhone via MonoTouch

    We are working on a version of the Dynamics CRM 4 SDK that will work with the iPhone via MonoTouch. Here is a preview of it creating an account in Dynamics CRM using the MonoTouch C# library. We're creating this to speed up development of xRM solutions that can leverage the power of touch based mobile devices as well as the Dynamics CRM platform.

  • 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!

  • 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();

  • 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

  • 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();