On one of our previous blog posts, we were demonstrating you simple example how you can use data from drop down and how to incorporate it to your own CRM entities. To modify it, we will use basic entities list inside of html Web resource for metadata to be available for further usage.

Create a New Project inside Visual Studio.

VS2013Project

Make a folder structure similar to next photo while following next requirements:

  • for GetAllEntities.htm; Add New Item by right clicking Web Resources.
  • for SDK.MetaData.js; Add Existing Item by selecting a JavaScript file from SDK SampleCode folder, available to download here (https://www.microsoft.com/en-us/download/details.aspx?id=50032)

In Properties for each file make an unique name following the pattern new_/GetAllEntities.htm, and for the JavaScript file, new_/js/SDK.MetaData.js.

FolderStructure

 

<!DOCTYPE html>
<html lang="en-US">
<head>
<link rel="stylesheet" href="css/style.css">
<title>Metadata Demonstration</title>
<script src="../ClientGlobalContext.js.aspx" type="text/javascript"></script>
<script type="text/javascript" src="js/SDK.MetaData.js"></script>

<script type="text/javascript">
function getEntities() { 

         SDK.Metadata.RetrieveAllEntities(SDK.Metadata.EntityFilters.Entity, 
          false, 
          successRetrieveAllEntities, 
          errorRetrieveAllEntities); 
     } 

function successRetrieveAllEntities(entityMetadataCollection) { 
 
    entityMetadataCollection.sort(function (a, b) { 
        if (a.LogicalName < b.LogicalName) 
        { return -1 } 
        if (a.LogicalName > b.LogicalName) 
        { return 1 } 
        return 0; 
      }); 
 
    for (var i = 0; i < entityMetadataCollection.length; i++) { 
      var entity = entityMetadataCollection[i]; 
      var select = document.getElementById("combobox");
      var el = document.createElement("option"); 
      el.textContent = entity.SchemaName; 
      el.value = entity.LogicalName; 
      select.appendChild(el);  
      } 
} 
 
function errorRetrieveAllEntities(error) {      
     setText(message, error.message); 
} 

function setText(node, text) { 
    if (typeof (node.innerText) != "undefined") { 
       node.innerText = text; 
    } else { 
      node.textContent = text; 
    } 
} 
</script> 
</head> 

<body onload="getEntities()" style="word-wrap: break-word;"> 
<select id="combobox"> <option>Choose an entity:</option>
    </select>
</body>
</html> 

Inside of a GetAllEntities.htm file, type the following code, and once deployed on your instance of CRM, Save it on Web Resources section, and then Publish it. Published resource can be inserted to your entity inside CRM, like explained on previous blog post. Opening the URL of HTLM page, you can see a image similar to this:

GetAllEntities

So, that’s it! Don’t forget that in similar way you can get any metadata you want. For example entity attributes, relationships or related entities; and later on use them inside your web resources in Microsoft Dynamics CRM.