Search code examples
asp.netdynamics-crm

i added a list box in asp.net , i need to get the option set values from ms crm to list box


I am new to ASP.Net I added a list box in asp.net , I need to get the option set values from ms crm to list box

I don't know how to return the value for this can anybody help me

public static string GetMtefrecord()
{ 
    var service = CRMWrapper.GetCRMService();

    RetrieveEntityRequest retrieveBankAccountEntityRequest = new RetrieveEntityRequest
    {
        EntityFilters = EntityFilters.Entity,
        LogicalName = "tec_new_mtfmtir",
    };
    RetrieveEntityResponse retrieveBankAccountEntityResponse = (RetrieveEntityResponse)service.Execute(retrieveBankAccountEntityRequest);
    //return retrieveBankAccountEntityResponse.LogicalName.ToString();
}

Solution

  • If your optionset is a global optionset, you can retrieve it using the RetrieveOptionSetRequest message. Here is a bit of sample code

    RetrieveOptionSetRequest retrieveOptionSetRequest =
    new RetrieveOptionSetRequest
    {
        Name = _globalOptionSetName //Put your optionsetname here
    };
    
    // Execute the request.
    RetrieveOptionSetResponse retrieveOptionSetResponse =
        (RetrieveOptionSetResponse)_serviceProxy.Execute(
        retrieveOptionSetRequest);
    
    OptionMetadata[] optionList =
         ((OptionSetMetadata) retrieveOptionSetResponse.OptionSetMetadata).Options.ToArray();