dynamics-crm Using Web API with jQuery Using the verbose option to get optionset and lookup values


Example

By default you will get de codes and id's for optionsets and lookups. If you want to get the label as well, you need to add an extra header to the call.

$.ajax({
    url: Xrm.Page.context.getClientUrl() + '/api/data/v8.0/contacts',
    headers: { 
        'Accept': 'Application/json', 
        'Prefer': 'odata.include-annotations="OData.Community.Display.V1.FormattedValue"' 
    }
}).done(function (result) {
    $.each(result.value, function (key, value) {
        //sample to access a label
        var gendercodeLabel = value['gendercode@OData.Community.Display.V1.FormattedValue'];
        var gendercodeValue = value.gendercode;
    });
});