Hello,
<html><head>
<meta charset="utf-8">
<style type="text/css">
body
{
background-color : #FFFFFF;
font-family:Segoe UI, Tahoma, Arial;
font-size:11px;
}
dynamicForm{
overflow-y:scroll;
}
td{
color: #3b3b3b;
font size=11px;
text-align: center;
}
select{
font-family:Segoe UI, Tahoma, Arial;
font-size:11px;
valign:top;
}
.tablabel{
font-size:15px;
font-weight:bold;
color:#1261e1;
font-family:Segoe UI, Tahoma, Arial
}
.sectionlabel{
font-size:13px;
font-weight:bold;
color:#3b3b3b;
font-family:Segoe UI, Tahoma, Arial
}
.section{
margin-left: 15px;
}
.attributeTable{
margin-left: 30px;
}
</style>
<script language="javascript" src="new_jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
function retrieveEntity() {
debugger;
var serverURL = parent.Xrm.Page.context.getClientUrl();
var Query = "EntityDefinitions?$select=DisplayName,EntitySetName,ObjectTypeCode";
var req = new XMLHttpRequest();
req.open("GET", serverURL + "/api/data/v9.1/" + Query, true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Prefer", "odata.include-annotations=*");
req.onreadystatechange = function() {
debugger;
if (this.readyState == 4 /* complete */ ) {
req.onreadystatechange = null;
if (this.status == 200) {
var data = JSON.parse(this.response);
if(data!=null && data.value !=null){
var AllentityMetadataCollection = data.value;
var entityMetadataCollection = [];
for(var i = 0; i <AllentityMetadataCollection.length; i++ ){
if(AllentityMetadataCollection[i].DisplayName && AllentityMetadataCollection[i].DisplayName.UserLocalizedLabel){
entityMetadataCollection[entityMetadataCollection.length] = AllentityMetadataCollection[i];
}
}
entityMetadataCollection.sort(function (a, b) {
if (a.DisplayName.LocalizedLabels[0].Label < b.DisplayName.LocalizedLabels[0].Label)
{ return -1 }
if (a.DisplayName.LocalizedLabels[0].Label> b.DisplayName.LocalizedLabels[0].Label)
{ return 1 }
return 0;
});
for (var i = 0; i < entityMetadataCollection.length; i++) {
var entity = entityMetadataCollection[i];
if($("#ddlallentity").length!=0){
if(entity.DisplayName.UserLocalizedLabel!=null){
$("#ddlallentity").append("<option value='"+entity.EntitySetName+"|"+entity.ObjectTypeCode+"|"+entity.MetadataId+"'>"+entity.DisplayName.LocalizedLabels[0].Label+"</option>");
}
}
else{
$("#ddlallentity").change(function (){
var entityName = $("#ddlallentity option:selected").text();
var entityLogicalName = $("#ddlallentity option:selected").val();
parent.Xrm.Page.getAttribute("new_entityname").setValue(entityLogicalName);
if($("#ddlattribute").length!=0){
$("#ddlattribute").empty()
}
});
}
}
}
} else {
var error = JSON.parse(this.response).error;
alert(error.message);
}
}
};
req.send();
}
function setLogicalNameofEntity(){
debugger;
var entityName = $("#ddlallentity option:selected").text();
var entLogicalName = $("#ddlallentity option:selected").val();
var entityLogicalName = $("#ddlallentity option:selected").val().split("|")[0];
var entityTypeCode = $("#ddlallentity option:selected").val().split("|")[1];
var entityMetadataId = $("#ddlallentity option:selected").val().split("|")[2];
parent.Xrm.Page.getAttribute("new_entityname").setValue(entityLogicalName);
parent.Xrm.Page.getAttribute("new_entitytypecode").setValue(entityTypeCode);
parent.Xrm.Page.getAttribute("new_entitymetadataid").setValue(entityMetadataId);
if($("#ddlattribute > option").length!=0){
$("#ddlattribute").empty();
$("#ddlattribute").css({
'min-width': '100px'
});
}
$('#dynamicForm').empty();
retrieveAttributes(attributesRetrieved,entityMetadataId);
}
function retrieveAttributes(attributesRetrieved,entityMetadataId) {
debugger;
var serverURL = parent.Xrm.Page.context.getClientUrl();
var Query = "EntityDefinitions("+ entityMetadataId.toUpperCase() +")?$select=LogicalName&$expand=Attributes($select=LogicalName,DisplayName)";
var req = new XMLHttpRequest();
req.open("GET", serverURL + "/api/data/v9.1/" + Query, true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Prefer", "odata.include-annotations=*");
req.onreadystatechange = function() {
debugger;
if (this.readyState == 4 /* complete */ ) {
req.onreadystatechange = null;
if (this.status == 200) {
var data = JSON.parse(this.response);
if(data!=null && data.Attributes!=null){
var AllAttributesCollection = data.Attributes;
var attributesCollection = [];
for(var i = 0; i <AllAttributesCollection.length; i++ ){
if(AllAttributesCollection[i].DisplayName && AllAttributesCollection[i].DisplayName.UserLocalizedLabel){
attributesCollection[attributesCollection.length] = AllAttributesCollection[i];
}
}
attributesCollection.sort(function (a, b) {
debugger;
if (a.DisplayName.LocalizedLabels[0].Label < b.DisplayName.LocalizedLabels[0].Label)
{ return -1 }
if (a.DisplayName.LocalizedLabels[0].Label> b.DisplayName.LocalizedLabels[0].Label)
{ return 1 }
return 0;
});
for (var i = 0; i < attributesCollection.length; i++) {
var attribute = attributesCollection[i];
if($("#ddlattribute").length!=0){
if(attribute.DisplayName.UserLocalizedLabel!=null){
$("#ddlattribute").append("<option value='"+attribute.LogicalName+"'>"+attribute.DisplayName.LocalizedLabels[0].Label+"</option>");
}
}
}
}
}
else {
var error = JSON.parse(this.response).error;
alert(error.message);
}
}
};
req.send();
}
window.onload = retrieveEntity;
</script>
<meta></head>
<body style="margin: 0px;">
<table height="1%" class="ms-crm-FormSection" id="{91951bf5-186c-4bb4-8d0b-80c807212b46}" style="table-layout: fixed;" cellspacing="0" cellpadding="3" valign="top" control="[object Object]" columns="2" label="General" isviewportsection="0">
<colgroup>
<col width="120">
<col>
<col width="140" class="FormSection_WriteColumnHeaders_col">
<col>
</colgroup><tbody>
<tr valign="top">
<td title="Entity" class="ms-crm-FieldLabel-LeftAlign ms-crm-Field-Normal" id="ddlallentity_c" style="text-align: left; font-size: 11px; color: #3b3b3b;"><label for="ddlallentity">Entity</label></td>
<td width="300" id="ddlallentity_d" isautoexpanding="FALSE" formxmlcolspan="1"><select name="ddlallentity" tabindex="1790" class="ms-crm-SelectBox " id="ddlallentity" style="float: left; -ms-ime-mode: auto; min-width: 100px;" onchange="setLogicalNameofEntity()" attrpriv="7" attrname="ddlallentity" req="0" defaultselected="-1"></select></td>
<td title="Field Name" class="ms-crm-FieldLabel-LeftAlign ms-crm-Field-Normal" id="ddlattribute_c" style="padding-left: 20px; font-size: 11px; color: #3b3b3b;"><label for="ddlattribute">Field Name</label></td>
<td id="ddlattribute_d" isautoexpanding="FALSE" formxmlcolspan="1"><select name="ddlattribute" tabindex="1880" class="ms-crm-SelectBox " id="ddlattribute" style="-ms-ime-mode: auto; min-width: 100px;" attrpriv="7" attrname="ddlattribute" req="0" defaultselected="-1"></select></td></tr></tbody></table>
<div id="dynamicForm"></div>
<div id="iframediv" style="display: none;"><iframe id="MyFormIframe">
</iframe></div></body></html>
I tried the above code,i am getting only the entity name in the dropdown based on the entity name not able to filter the field name,through this code how to filter the Attribute based on the entity,please suggest me.
*This post is locked for comments