javascriptdynamics-crmentityoptionsettypexrmservicetoolkit

Dynamics CRM getting global OptionSet data using XrmServiceToolkit.Soap


When using Dynamics CRM 365, I would like to find a way to get the labels and values from a global OptionSet, using the Javascript library "XrmServiceToolkit" and the Soap method (we need it to be async).

Thanks.


Solution

  • The solution I found working:

    Getting all the attributes of the OptionSet:

    var myOptionSetData = XrmServiceToolkit.Soap.RetrieveAttributeMetadata('entity_logical_name_that_contains_a_field_with_the_optionset', 'optionset_logical_name', false);
    

    Afterwards you can access the values and labels like so:

    var last = myOptionSetData[0].OptionSet.Options.length - 1;
    var vals = [];
    var labels = [];
    
    for (var idx = 0; idx <= last; idx++)
    {
        vals.push(parseInt(myOptionSetData[0].OptionSet.Options[idx].Value));
        labels.push(myOptionSetData[0].OptionSet.Options[idx].Label.UserLocalizedLabel.Label)
    }
    

    Hope it helps someone.