Knowledge found and lost while working with Microsoft Dynamics CRM
RSS icon Home icon
  • Enhancing CRM 4: Workflows vs. Plugins

    Posted on June 4th, 2008 mitch Print Print 5 comments

    Back in the dark ages, like with CRM 3.0, we were often faced with writing .NET code to provide certain enhanced data manipulation capabilities as either Callouts or Workflow Assemblies.  CRM 4.0 totally changes that mind set – and as a solution developer, you really need to keep that in mind before you jump off into the depths of Visual Studio and the CRM SDK.

    An Example

    To illustrate my point, let's take the PostInvoicePlugin example from the CRM SDK ( v4.0.5 ).

    Note: this example is found in the SDK folder: sdkserverfullsamplepluginpostinvoice

    The purpose of this sample code is to show you how to update a custom field on the Account record whenever a user closes out an Invoice as Paid.  The plugin checks the state of the Invoice, and if Paid, it will update the value of a custom field on Account, using the following code:

    // If the Total Invoiced exists, update it... otherwise set it
    if (parentAccount.Properties.Contains("new_totalinvoiced"))
    {
        ((CrmMoney)parentAccount.Properties["new_totalinvoiced"]).Value += totalAmount;
    }
    else
    {
        parentAccount.Properties.Add(new CrmMoneyProperty("new_totalinvoiced",
                                     new CrmMoney(totalAmount)));
    }
    

    Pretty cool, huh?

     

    An Alternative

    If you haven't spent much time reviewing CRM 4.0 workflows, you should.  You can perform some amazing things without ever writing code.  Let's perform the exact same steps using CRM 4.0 workflow.

    First, we create a workflow based on the Invoice Entity that has the following properties:

    image

    Step 1:

    Create a Check Condition using the following information:

    image

    Step 2:

    Add and Update Record step, on the Related Entity Customer (Account):

    image

    Step 3:

    Click the Set Properties button, then set the Total Invoiced Attribute to the following:

    image 

    Note: Total Invoiced is a custom Money Field.

    By using the Increment by Operator, we are able to increment any existing Total Invoiced amount by the amount found in the Invoice's Total Amount field.

    Final Step:

    Save and Publish this workflow.

    Conclusion:

    So, is there a difference between these techniques?  Not really.  Both accomplish the job in a very similar manner but the Workflow solution requires zero code maintenance and a normal user or administrator can create the workflow.

    The biggest difference between the two techniques is in the timing of the actual update. Plugins can be executed either Synchronously or Asynchronously.   Workflows function in an asynchronous manner.

    The Synchronous operation will modify the data stream as it is being saved to the database, which can introduce a delay in the user's experience, but will provide results back to the user in a quicker fashion.

    Asynchronous operations will happen shortly after the data has been saved which will not impact the user, but which may result in a slight delay between the time the user saved the record and when the value will be updated.

    If you can live with the time delay, I feel that workflow is the way to go, in most cases.  If you can't, then download the SDK and start working through their examples.

    Customization, Development, Dynamics CRM, Workflow
    1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...
    7,897 views
  • CRM 4.0 Workflow: Adding a timestamp to a field

    Posted on May 22nd, 2008 mitch Print Print No comments

    One of my current projects required that we have, more or less, an audit log for completion of tasks.  This can be easily accomplished using a CRM 4.0 workflow, using the following variables:

    image

    When the workflow is run, it will produce the following results:

    image 

    In this particular case, we are actually creating a task, then setting the Task Status to Completed so that it gets placed in the history for the record.

    Dynamics CRM, Workflow
    1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...
    1,263 views
  • Guest article on CRM Team blog. 2/6/2008

    Posted on February 6th, 2008 mitch Print Print No comments

    I have an article on the CRM Team Blog describing how to automate the sending of a welcome email to new CRM users using CRM 4.0 workflow.

    Dynamics CRM, Workflow
    1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...
    2,020 views
  • CRM 4.0 Workflow: Setting the Primary Contact's Parent Customer

    Posted on January 21st, 2008 mitch Print Print 8 comments

    I am becoming more and more impressed with the workflow capabilities of CRM 4.0.  I am finding that I can create workflows to automate minor tasks to enhance CRM's functionality or to correct what I consider to be "annoyances."

    One of these involves the relationship between the Primary Contact for an Account and that Contact's Parent Customer field. 

    When I set the Primary Contact on an Account, I would like it to automatically edit that Contact's record and update the Parent Customer field to point back to the Account.  It's always seemed fairly logical to me to have these two fields linked, but that's not the way it has worked, until now.

    We're going to define a workflow based on the Account Entity ( I've renamed my Account Entity to be Company, but it works just the same ).  Here's how the initial workflow configuration will look:

    image

    Options:

    Start when:

    • Record is created
    • Record attributes change ( select the Primary Contact Attribute )

    Available to Run:

    • On demand

    Steps:

    1) Check for existing data

    1a) If the Primary Contact's Parent Customer Attribute does not contain data, perform the next step:

     image

    ( Basically, if the user has set the Attribute manually, we don't wish to overwrite their work. )

    2) Update the Related Entities: Primary Contact record.

    3) Set the Parent Customer Attribute:

    image

    This will make our workflow look like this:

    image

    Publish the workflow.  From this point forward, every time you set the Primary Contact for an Account, the workflow rule will run and if you have not already, it will update the Primary Contact's Parent Customer Attribute to point to the Account.

    Dynamics CRM, Workflow
    1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...
    3,717 views