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.
Hello,
Just add the code
if (!!Xrm.Page.getAttribute("crc1e_csosubmitteremail").getValue()) {
return;
}
At the very beginning of your onload handler.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156