locked
CRM2011: Address - AddressTypeCode optionset metadata RRS feed

  • Question

  • Hi All,

    I'm trying to get the metadata for the 'AddressTypeCode' field on the Address (More Addresses) entity in a plugin.

    Everytime i use 'addresstypecode' i keep getting an error back saying "could not find optionset".

    Does anyone know that the name of the 'addresstypecode' attribute is on the address (customeraddress) entity?

    Thanks in adv for any help,

    Monday, May 12, 2014 3:02 PM

Answers

  • Hi bshah,

      Use following code to retrieve AddressTypecode metadata (it working fine for me)

    RetrieveAttributeRequest attributes = new RetrieveAttributeRequest();

                    attributes.EntityLogicalName = "customeraddress";

                    attributes.LogicalName = "addresstypecode";

                    attributes.RetrieveAsIfPublished = true;

                    RetrieveAttributeResponse responsee = (RetrieveAttributeResponse)service.Execute(attributes);

                    PicklistAttributeMetadata picklistmetadata = (PicklistAttributeMetadata)responsee.AttributeMetadata;

                    OptionMetadata[] optionlist = picklistmetadata.OptionSet.Options.ToArray();

                    Console.WriteLine("Options Retrieved");

                    foreach(OptionMetadata option in optionlist)

                    {

                        Console.Write("Value: " + option.Value.ToString());

                        Console.WriteLine("Text:  " + option.Label.UserLocalizedLabel.Label.ToString());

                        Console.Read();

                    }


    • Edited by Gugan A Tuesday, May 13, 2014 9:01 AM
    • Marked as answer by bshah1985 Tuesday, May 13, 2014 9:02 AM
    Tuesday, May 13, 2014 5:52 AM

All replies

  • Hi bshah,

      Use following code to retrieve AddressTypecode metadata (it working fine for me)

    RetrieveAttributeRequest attributes = new RetrieveAttributeRequest();

                    attributes.EntityLogicalName = "customeraddress";

                    attributes.LogicalName = "addresstypecode";

                    attributes.RetrieveAsIfPublished = true;

                    RetrieveAttributeResponse responsee = (RetrieveAttributeResponse)service.Execute(attributes);

                    PicklistAttributeMetadata picklistmetadata = (PicklistAttributeMetadata)responsee.AttributeMetadata;

                    OptionMetadata[] optionlist = picklistmetadata.OptionSet.Options.ToArray();

                    Console.WriteLine("Options Retrieved");

                    foreach(OptionMetadata option in optionlist)

                    {

                        Console.Write("Value: " + option.Value.ToString());

                        Console.WriteLine("Text:  " + option.Label.UserLocalizedLabel.Label.ToString());

                        Console.Read();

                    }


    • Edited by Gugan A Tuesday, May 13, 2014 9:01 AM
    • Marked as answer by bshah1985 Tuesday, May 13, 2014 9:02 AM
    Tuesday, May 13, 2014 5:52 AM
  • Thank you Gugan A - that worked! :-)
    Tuesday, May 13, 2014 9:02 AM