Knowledge found and lost while working with Microsoft Dynamics CRM
RSS icon Home icon
  • Retrieving State and Status Options via the MetadataService

    Posted on June 9th, 2009 mitch Print Print No comments

    As you probably know, the State and Status options for a CRM entity are linked together.  You can’t change the State options or values but you can change the Status options ( which are generally shown in a picklist ).

    On a recent project, I needed to simulate the Cancel Opportunity dialog through a custom user interface.  Rather than build a hard-coded list of reasons for the cancelation, I decided to use the CRM MetadataService to dynamically pull the data using the following method ( in C# ):

    public SortedList RetrieveStatusList(
                          string entityName,
                          int statusValue)
    {
        SortedList list = new SortedList();
    
        AttributeMetadata attMetaData;
        RetrieveAttributeRequest request =
            new RetrieveAttributeRequest();
        request.EntityLogicalName = entityName;
        request.LogicalName = "statuscode";
        RetrieveAttributeResponse response;
    
        response =
            (RetrieveAttributeResponse)metadataService.Execute(request);
        attMetaData = response.AttributeMetadata;
    
        StatusAttributeMetadata status =
            (StatusAttributeMetadata)attMetaData;
    
        foreach (StatusOption o in status.Options)
        {
            if (o.State.Value == statusValue)
            {
                list.Add(o.Label.UserLocLabel.Label,
                         o.Value.Value.ToString());
            }
        }
    
        return list;
    }

    The method takes two parameters:

    1. The entity name
    2. The state code value

    I am using this method to populate a ASP.NET dropdown list box using the following code:

    DropDownList1.DataSource = RetrieveStatusList("opportunity", 2);
    DropDownList1.DataTextField = "Key";
    DropDownList1.DataValueField = "Value";
    DropDownList1.DataBind();

    In the case of the Opportunity, we have the following State code values:

    Name Value
    Lost 2
    Open 0
    Won 1

     

    Since we are canceling an Opportunity, we use the Lost state, which has a value of 2.

     

    How This Works

    The key to making sense of this process is the StatusOption object.  It contains data for both the Status Reason codes and the State with which are they associated.

    Since we are looking for a specific state, we check the State for the Option and if it matches our expected value, we add it to the list.

    Customization, Development, Dynamics CRM
    1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...
    131 views
  • Visual Studio Icon Library

    Posted on February 24th, 2009 mitch Print Print No comments

    I just love accidentally finding valuable information. While looking for something totally different, I found this article by Sara Ford.

    Starting in Visual Studio 2005, you’ll find the Visual Studio Image Library, a zip file that contains over a 1000 images to create applications that have a consistent UI look and feel to Windows, Office, and Visual Studio.

    During the Visual Studio setup, the VS2008ImageLibrary.zip file is installed at \Program Files\Microsoft Visual Studio 9.0\Common7\VS2008ImageLibrary\

    Judging from the comments on the article, I'm not sure many people knew this was there.

    One of the cooler things included in the library are some of those animated icons you see on long operations such as moving, copying, and uploading files.   A few months ago, I probably spent a couple of hours browsing around the web for examples of those.

    Thanks Sara.

    Development
    1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
    Loading ... Loading ...
    487 views
  • Blast from the past: an alternative to a progress bar

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

    I was installing Visual Studio 2008 SP1 today when I noticed that in addition to two different progress bars, they had an alterative progress indicator.  It is purely text based and is fairly simple to implement and consists of the following characters:

     

    \

    |

    /

     

    If you display these characters one after the other, in the order specified above, you will create something we used to call a "spinner," which is has the appearance of a spinning bar.  The spinner will spin at different speeds, depending on how fast you cycle through characters.  This is a great technique for keeping the user informed when you're performing a long operation.  Theoretically, as long as the spinner is spinning, you're application is still working and no hung up in some way.  It's not as flashy as a progress bar, but it can be just as effective.

    I have not seen this technique used in years ( actually a bunch of years ) but it's good see that some of the old ways still work.

    Development
    1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...
    547 views
  • Happy weekend everyone

    Posted on September 26th, 2008 mitch Print Print No comments

    It's been a while since I posted anything of relevance so I wanted to say hi to everyone and let you know I'm still alive and kicking and to wish everyone a happy weekend.

    I've been heads-down in about three separate CRM or CRM-related projects and haven't had time to write anything new – but I do have things coming.

    Being so CRM focused sometimes leaves me out of the loop when it comes to other, development-related matters.  Case in point: Just this morning, I was looking at the Visual Studio start page and I see this article:

    How Do I: Create a Basic Language Service Using the Managed Babel System?

    Which, as everyone knows, is about this:

    Create a basic language service by using the Managed Babel System infrastructure provided in the Visual Studio 2008 Software Development Kit (SDK). Incorporate the syntax for your language using the Managed Package Lex Scanner Generator (MPLex) and Managed Package Parser Generator (MPPG) tools and set up and register your language service into the Visual Studio environment. Hilton Giesenow demonstrates how.

    Huh?

    I think I'll crawl back into my CRM cave and worry about managing my Babel at some point in the future…

    Peace out.

    Development, Misc
    1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...
    643 views
  • 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,900 views
  • Applying Visualization to Software Development

    Posted on May 30th, 2008 mitch Print Print 3 comments

    Over the past several years, I have read and seen multiple references to a practice called Visualization, which is when a person rehearses a physical action by performing the task mentally.

    Examples that come to mind are the NASA astronaut training program, Olympic athletes, and the Navy's Blue Angels. 

    Note: You can perform an Internet search on Visualization and any of the above topics and find a host of articles for further reading.

    Earlier this week, I was shocked ( and a bit astounded ) to find that I actually use Visualization techniques myself in the course of my software development.

    I was shocked not because I was doing it, but because I have always done it and didn't know it had a name and that other people were using similar techniques to mentally rehearse physical actions.  Pretty weird, I thought.

    I am mentioning it here because I am curious if other solution developers have a similar practice.

    How I use Visualization

    When presented with a problem in need of a solution, I like to let the problem bounce around inside my head for a while as I examine the issue from all sides. This allows me to present arguments ( to myself ) and accept and/or counter those arguments until I have what I feel is a viable solution.  If working on a multi-member project team, I then present the solution for further refinement.  If working on a project by myself, I usually create a prototype to see if my solution is viable.

    Most of this work is done without ever touching a keyboard.  While it may not appear that I am "working," I am also not creating anything that must be discarded, which I think saves time overall.  Sometimes this process happens quickly, sometimes it may take days – depending on urgency and the type of problem I'm working on.

    So Does Visualization Make a Difference?

    Well, I have no quantifiable data to present, but I think that it does make a difference in my work.

    I think the biggest contribution of Visualization is the ability to "think through" the user experience (UX). By creating "pictures" of the user interface in my mind, I can quickly discover unforeseen paths that can either enhance or detract from the user's overall experience.

    After thinking about the UX for a while, I will sometimes even go so far as to walk through the solution's critical path and design data structures, program flow, and other features that make up the solution.

    This can be as simple as a CRM form design or as complicated as a .NET Windows Forms application.

    And, I can't tell you how many times this "walk though" has arrived at a solution that not only more useful than the overall requirements or specification stated, but many times it produces features that I did not anticipate when I initially drew up the specs.

    Finally, it also helps you decided what really needs to be presented to a user.  I think a lot of developers ( myself included ) have a tendency to provide too much information or too many options to the user.  The Visualization of the UX allows you to ask the question, "Does the user really need that, there?"

    Final Thoughts

    I am a firm believer in simplicity in design, which is properly represented by one of my favorite quotes:

    When I am working on a problem, I never think about beauty but when I have finished, if the solution is not beautiful, I know it is wrong.
    R. Buckminster Fuller

    I can't tell you the number of times that I have looked at something, either from a UX perspective or at the actual code itself, and just knew it was wrong.

    Complicated designs tend not to be beautiful, or elegant, and are therefore prone to failure in either design or execution.  I think that Visualization helps me to design elegant solutions to everyday problems that I and my customers face.

     

    I'd love to hear from you regarding this topic.  If you use similar techniques or have other thoughts, just leave a comment on this article ( or drop me an email ).

    Development
    1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...
    986 views
  • SQL Server Version Numbers

    Posted on March 28th, 2008 mitch Print Print No comments

    I found a handy site today that lists version numbers for Microsoft SQL Server and what is installed to obtain a specific version:

    http://www.sqlsecurity.com/FAQs/SQLServerVersionDatabase/tabid/63/Default.aspx

    Development, Dynamics CRM
    1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...
    1,010 views
  • The Science of Experience

    Posted on March 16th, 2008 mitch Print Print No comments

    I was out of the office for a week and decided to catch up on my blog reading this afternoon. While reading one of Scott Hanselman's posts when I took his advice to read the post "What does it take to be a grandmaster" by Jeff Moser.  Jeff's article mentioned a Time Magazine article entitled The Science of Experience which described the work of Anders Ericsson, who is an expert on experts.  His research has produced the following fascinating piece of information:

    Ericsson's primary finding is that rather than mere experience or even raw talent, it is dedicated, slogging, generally solitary exertion — repeatedly practicing the most difficult physical tasks for an athlete, repeatedly performing new and highly intricate computations for a mathematician — that leads to first-rate performance. And it should never get easier; if it does, you are coasting, not improving. Ericsson calls this exertion "deliberate practice," by which he means the kind of practice we hate, the kind that leads to failure and hair-pulling and fist-pounding. You like the Tuesday New York Times crossword? You have to tackle the Saturday one to be really good.

    Wow!  This should not have come as a shock to me, but it did.  I guess, like most people, I just needed the cold hard data to make things clear.

    I have long believed in the fact that if anyone could do it, they would.  Which is why I think there are actually so few people doing cutting-edge work – because it's hard.

    Throughout my career I've had opportunities to work on some fascinating projects with some amazing ( at the time ) products.  But, I always noticed that at some point in time, when you've learned pretty much all you can learn about something, it gets boring. 

    Boring = Coasting. Coasting = Not Improving.  Not Improving = Not Growing.

    And if you're not growing, what the heck use are you anyway?

    Well, with the introduction of CRM 4.0, I'm back to learning a whole new bunch of stuff all over again.  I guess it's time to put down the Cheetos, get off the couch and jump neck-deep back into learning how CRM 4.0 works, and more importantly, how to make it work. :)

    Both Jeff's article and the Time Magazine article are worth reading and full of interesting information.  Read both when you have time.

    Development
    1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...
    733 views
  • On my bookshelf this morning…

    Posted on November 15th, 2007 mitch Print Print No comments

    I noticed this:

    tpascal

    Circa 1987.

    Ah, those were the days….

    Development, Misc
    1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...
    874 views
  • Errors when sending email from CRM

    Posted on August 10th, 2007 mitch Print Print 1 comment

    I ran into the following error message yesterday while sending email from the CRM Web Client:

    bad_email_setup

    This was on a CRM Professional installation with the CRM and Exchange existing on different servers.

    The following article walks you through various troubleshooting steps required to determine the root cause of the issue.

    How to configure the outgoing e-mail functionality in Microsoft Dynamics CRM 3.0.

    In this particular case, we found that an anti-virus application had blocked port 25 which is the SMTP port that CRM uses to send email to the Exchange server.

    Attempts to utilize Telnet to communicate with the Exchange server ( telnet Server_name 25 ) failed which indicated that something was blocking the communication between the two servers.  After determining that the anti-virus application was causing the issue, we reconfigured the software to open port 25 and email was flowing normally.

    Development, Dynamics CRM
    1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...
    1,676 views