Hi,
I am using this JS script to populate two blank fields OnLoad of the Main form. How can I amend this so that, if these fields are already populated, don't "over-write" them?
function onFormLoad() {
var userId = Xrm.Page.context.getUserId();
var request = new XMLHttpRequest();
var newuserId = userId.replace(/{|}/g, "");
var emailAddressField = Xrm.Page.getAttribute("crc1e_csosubmitteremail");
request.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/systemusers(" + newuserId + ")?$select=internalemailaddress", true);
request.setRequestHeader("OData-MaxVersion", "4.0");
request.setRequestHeader("OData-Version", "4.0");
request.setRequestHeader("Accept", "application/json");
request.setRequestHeader("Content-Type", "application/json; charset=utf-8");
request.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
request.onreadystatechange = function() {
if (this.readyState === 4) {
request.onreadystatechange = null;
if (this.status === 200) {
var user = JSON.parse(this.response).value;
var emailAddress = user[0].internalemailaddress;
emailAddressField.setValue(result["internalemailaddress"]);
}
else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
request.send();
var userName = Xrm.Page.context.getUserName();
Xrm.Page.getAttribute("new_csosubmittername").setValue(userName);
}
Thanks
K.