How to query the Metadata Service via JavaScript

A very useful post

Example (Jscript) –

/* ********************************************************
gQueryMetadataService() function
Description: Generic function to call the metadata webservice
Calls by : gGetEntityProperty
Returns: XML response array
parameters for examole:
– MetadataItems – The items you wish to retrieve e.g. EntitiesOnly, IncludeAttributes, IncludePrivileges, IncludeRelationships and All.
– RetrieveAsIfPublished – specifies whether you want to get a list of just the published entity metadata or all of the entity metadata.
var request = “<Request xsi:type=’RetrieveAllEntitiesRequest’>” +
“<MetadataItems>EntitiesOnly</MetadataItems>” +
“<RetrieveAsIfPublished>false</RetrieveAsIfPublished>” +
var result = gQueryMetadataService(request);
var logicalNames = result.selectNodes(“//CrmMetadata/LogicalName”);
gQueryMetadataService = function(request) {
var xmlhttp = new ActiveXObject(“Msxml2.XMLHTTP”);“POST”, ‘/mscrmservices/2007/MetadataService.asmx’, false);
xmlhttp.setRequestHeader(“Content-Type”, “text/xml; charset=utf-8”);
xmlhttp.setRequestHeader(“SOAPAction”, ‘;);
var soapMessage = “<?xml version=’1.0′ encoding=’utf-8′?>” + “<soap:Envelope xmlns:xsi=’; ” + “xmlns:xsd=’; xmlns:soap=’’>&#8221; + GenerateAuthenticationHeader() + “<soap:Body><Execute xmlns=’’>&#8221; + request+ “</Execute></soap:Body>” + “</soap:Envelope>”;
return xmlhttp.responseXML;


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: