Retrieve CRM 2013 State and Status Code using JavaScript.

With the help of  oData we can get the value of the statuscode field but not for the statecode field. While looking for the best possible way to get the statecode alongwith the statuscode in javascript came to know about the sdk.metadata.js sample code in SDK (sdk\samplecode\js\soapforjscript\soapforjscript\scripts)

There is a RetrieveAttribute method which can be used to get the attribute metadata.This is how we fetched all the label and value for the state and status in CRM.

function GetEntityStateAndStatus(EntityName) {
    var AttributeLogicalName = "statuscode";
    var MetadataId = "00000000-0000-0000-0000-000000000000";
    SDK.Metadata.RetrieveAttribute(EntityName, AttributeLogicalName, MetadataId, true,
    function (result) {
        SDK.SAMPLES.success(result);
    },
    function (error) { }
    );
}
function successCallBack(result) {
    for (var i = 0; i < result.OptionSet.Options.length; i++) {
        var stateValue = result.OptionSet.Options[i].State;
        var statusValue = result.OptionSet.Options[i].Value;
        var statusText = result.OptionSet.Options[i].Label.LocalizedLabels[0].Label;
    }
}