Hi, I really appreciate your answers but what I want to achieve is something like this in portal custom Javascript:
// Retrieve entity metadata
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: webApiUrl + 'EntityDefinitions(LogicalName=\'' + entityLogicalName + '\')?$select=EntityId',
beforeSend: function (xhr) {
xhr.setRequestHeader("OData-MaxVersion", "4.0");
xhr.setRequestHeader("OData-Version", "4.0");
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Prefer", "odata.include-annotations=*");
},
success: function (entityMetadata) {
var entityId = entityMetadata.EntityId;
// Retrieve attribute metadata
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: webApiUrl + 'EntityDefinitions(' + entityId + ')?$select=LogicalName&$expand=Attributes($filter=LogicalName eq \'' + attributeLogicalName + '\')',
beforeSend: function (xhr) {
xhr.setRequestHeader("OData-MaxVersion", "4.0");
xhr.setRequestHeader("OData-Version", "4.0");
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Prefer", "odata.include-annotations=*");
},
success: function (attributeMetadata) {
var attribute = attributeMetadata.Attributes[0];
var maxLength = attribute.MaxLength;
console.log('Max length of ' + attributeLogicalName + ' field: ' + maxLength);
},
error: function (error) {
console.error('Error retrieving attribute metadata:', error.statusText);
}
});
},
error: function (error) {
console.error('Error retrieving entity metadata:', error.statusText);
}
});
On the other hand, as expected, below piece of code is working when it runs within CRM but it is not applicable in portal:
req.open("GET", globalContext.getClientUrl() + "/api/data/v9.0/EntityDefinitions(LogicalName ..etc