Now I try to replace label control display name of "Phone" with description.
This is the JS code and I will post the code on the back.
Then refresh and the display name of Phone is changed.
function changeLabel(e){
var req = new XMLHttpRequest();
var formContext = e.getFormContext();
req.open("GET", Xrm.Utility.getGlobalContext().getClientUrl() + "/api/data/v9.0/EntityDefinitions(LogicalName='cr932_students')/Attributes?$select=SchemaName,Description", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var results = JSON.parse(this.response);
for (var i = 0; i < results.value.length; i++) {
if(results.value[i].SchemaName=="cr932_Phone"){
var newLabel= results.value[i].Description.LocalizedLabels[0].Label
console.log(newLabel);
formContext.getControl("cr932_phone").setLabel(newLabel)
}
}
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}