Dynamics CRM 2011 Online plugin - How do I retrieve the value of an option?

Navržená odpověď Dynamics CRM 2011 Online plugin - How do I retrieve the value of an option?

  • Saturday, June 16, 2012 8:09 AM
     
      Has Code

    I'm trying to retrieve the selected option of a "Two Options" DataType in a customized form.  The options appear as radio buttons and are a simple 'True' (value = 1) and 'False' (value = 0).

    My plugin is set to run on update of salesorder entity, synchronously, with a Post Image named "postBookingImage".  The followng code:

                tracer.Trace("Attempting to find postImage");
                if (context.PostEntityImages.Contains("postBookingUpdate"))
                {
                    tracer.Trace("postBookingUpdate Image Found");
                    Entity bookingImage = (Entity)context.PostEntityImages["postBookingUpdate"];
                    tracer.Trace("Created bookingImage");
                    //Try Catch Block - Attempting to find out if creation or a consumption booking
    
                    try
                    {
                        if (bookingImage["new_creationbooking"].Equals(0))
                        {
                            tracer.Trace("Consumption Booking");
                        }
                        if (bookingImage["new_creationbooking"].Equals(1))
                        {
                            tracer.Trace("Creation Booking");
                        }
                    }
                    catch (Exception e)
                    {
                        tracer.Trace("uh oh.  something bad happened");
                        tracer.Trace(e.ToString());
    
                    }
    }

    gives me the error message:

    Created bookingImage
    System.NullReferenceException: Object reference not set to an instance of an object.
       at McGheePlugins.UpdateOAPContractSold.Execute(IServiceProvider serviceProvider)
    Not an OAP Creation Booking
    

    Does anyone have any suggestions?

    Much appreciated,

    -Dan

    gives me the exception:


    Dan Packer

All Replies

  • Saturday, June 16, 2012 11:25 AM
     
     Proposed Answer

    Your said in the second line that image name is postBookingImage but in the code you are using postBookingUpdate.


    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Amreek Singh Senior CRM Consultant CDC Praxa Sydney, Australia http://mscrmshop.blogspot.com http://crm2011usersettings.codeplex.com

    • Proposed As Answer by Amreek Singh Monday, June 18, 2012 12:00 PM
    •  
  • Saturday, June 16, 2012 9:17 PM
     
      Has Code

    Hello :

    From the error you told, I can think of 2 issues

    1.

    Entity bookingImage = (Entity)context.PostEntityImages["postBookingUpdate"];
    

    bookingImage: does not contains this attribute ["new_creationbooking"]

    2. Try to get the value of the optionset as

    if (bookingImage.Attributes["new_creationbooking"] == false) { tracer.Trace("Consumption Booking"); } if (bookingImage.Attributes["new_creationbooking"] == true) { tracer.Trace("Creation Booking"); }

    Let me know for further help


    Saurabh Gupta, MS CRM 2011 Software Development Engineer

  • Sunday, June 17, 2012 3:42 PM
     
     

    Thanks for catching that - the correct name is postBookingUpdate (I mis-typed it in the description); the plugin seems to be correctly referencing the image.


    Dan Packer

  • Monday, June 18, 2012 12:01 PM
     
     

    if its working. could you please mark my post as answer?

    Regards


    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Amreek Singh Senior CRM Consultant CDC Praxa Sydney, Australia http://mscrmshop.blogspot.com http://crm2011usersettings.codeplex.com

  • Tuesday, June 19, 2012 9:48 AM
     
     

    You may have to use System.Boolean.FalseString and System.Boolean.TrueString instead of 0 and 1. It.helped me out.

    Thanks


    Haris Adil e-Bizsoft