locked
Check to see if Option Set is null?? Plugin RRS feed

  • Question

  • Hi everyone,

    I have a plugin registered on the Pre-Operation, Create of an Email.

    I am having trouble checking to see if the Option Set (new_sendto) is populated.

    Here is some sample code:

       Entity email = (Entity)pluginExecutionContext.InputParameters["Target"];
    
     var contact = context.OrganizationService.Retrieve("contact",
                            ((EntityReference)activityParty["partyid"]).Id, new ColumnSet(emailAddressFields));
    
                            //Check to see if Email exist in the specified CRM field
                            if (!contact.Attributes.Contains(emailLogicalName) && !email.Attributes.Contains("new_sendto"))
                            {
                                tracingService.Trace("No Email address in Contact and Sent To not populated");
                                LoopEmailAddresses(tracingService,emailAddressFields, emailLogicalName, contact);
                            }

    I have the OptionSet in my form.

    I get the error... the key is not present in the dictionary.

    Fails when I include

    !email.Attributes.Contains("new_sendto")

    I have also tried

    !email.Attributes["new_sendto"]==null;

    Still get the same error....

    Code seems to be running fine when I remove the exclamation mark.....

    How do I go about to check if the option set is being populated or not???

    Many Thanks

    Tuesday, January 14, 2014 10:47 PM

All replies