Column type?

Jun 11, 2013 at 10:06 AM
Hi,

First off thanks for the tool, I spent a bit of time looking at using this or the SDK example and eventually picked CrmRestKit - so far so good :)

Is there a way to get the column type from the returned data set?

I've tried:
var ty = typeof data.d.results[i]["my_column"];
But that just brings back string for everything.

I've found examples in the SDK I could work from but thought it worth checking if there is a simple way to do this

Thanks! :)
Coordinator
Jun 12, 2013 at 6:56 AM
Hi,

the approch with typeof will not work. You need to call the meta-data webservice to fetch this data. The SDK contains the "sdk.metadata.js" script ("%\Dynamics CRM 2011 SDK 5.0.15\sdk\samplecode\js\soapforjscript\soapforjscript\scripts").

The nice thinks is that you could easly combine this script with the promise-pattern:
///
/// Loads the metadata for an entity, per default only the attribute-metadata is loaded
/// the last parameter could be used to load relationships, privileges, all
/// 
function getMetadata( logicalEntityName, opt_filter ) {

    var dfdmetadata = new $.Deferred(),
        filter = opt_filter || SDK.Metadata.EntityFilters.Attributes;

    // load attribute meta-data
    SDK.Metadata.RetrieveEntity( filter, logicalEntityName, null, true, dfdmetadata.resolve, dfdmetadata.reject );
    

    // return the promise not the defered-object 
    return dfdmetadata .promise();
}
Regards,

Daniel
Marked as answer by thuld on 10/10/2013 at 12:26 AM
Jun 17, 2013 at 6:06 PM
Oops sorry thought I had replied - thanks for that, very useful! I had come up with a pretty similar method but without the promise - good bit of JS to get my head around.

Thanks!

Kuba