Retrieve entity related attribute by SDK.Metadata.RetrieveEntity using javascript in mscrm
function addColumn(entityName) {
if (entityName != null && entityName != undefined && entityName != "") {
SDK.Metadata.RetrieveEntity(SDK.Metadata.EntityFilters.Attributes, entityName, null, false, function (entityMetadata) { successRetrieveEntityData(entityName, entityMetadata); }, errorRetrieveEntity);
}
}
function successRetrieveEntityData(logicalName, entityMetadata) {
attributecount = null;
attributes = [];
attributecount = entityMetadata.Attributes.length;
entityMetadata.Attributes.sort(function (a, b) {
if (a.LogicalName < b.LogicalName)
{ return -1 }
if (a.LogicalName > b.LogicalName)
{ return 1 }
return 0;
});
var attribute = null;
//attribute += "<td><select id='trr" + rowCount + "'>";
//attribute += "<option value='select'>--Select--</option>";
for (var i = 0; i < attributecount; i++) {
attributes.push(entityMetadata.Attributes[i].LogicalName);
attribute += "<option value='td1" + attributes[i] + "'>" + attributes[i] + "</option>";
}
// attribute += "</select></td>";
$('#trr' + rowCount).append(attribute);
// setTimeout(function () { alert("Hello"); }, 5000);
}
function errorRetrieveEntity(error) {
alert("Error!");
}
if (entityName != null && entityName != undefined && entityName != "") {
SDK.Metadata.RetrieveEntity(SDK.Metadata.EntityFilters.Attributes, entityName, null, false, function (entityMetadata) { successRetrieveEntityData(entityName, entityMetadata); }, errorRetrieveEntity);
}
}
function successRetrieveEntityData(logicalName, entityMetadata) {
attributecount = null;
attributes = [];
attributecount = entityMetadata.Attributes.length;
entityMetadata.Attributes.sort(function (a, b) {
if (a.LogicalName < b.LogicalName)
{ return -1 }
if (a.LogicalName > b.LogicalName)
{ return 1 }
return 0;
});
var attribute = null;
//attribute += "<td><select id='trr" + rowCount + "'>";
//attribute += "<option value='select'>--Select--</option>";
for (var i = 0; i < attributecount; i++) {
attributes.push(entityMetadata.Attributes[i].LogicalName);
attribute += "<option value='td1" + attributes[i] + "'>" + attributes[i] + "</option>";
}
// attribute += "</select></td>";
$('#trr' + rowCount).append(attribute);
// setTimeout(function () { alert("Hello"); }, 5000);
}
function errorRetrieveEntity(error) {
alert("Error!");
}
Comments
Post a Comment