We just migrated from CRM 2011 to CRM 2016.
We are having a problem with one script that throws an error. The script is called on the case form when the contact is updated and when the form is saved. The script works fine if the contact field has a value, but it the field is empty, we get the error:
Javascript error: TypeError: Cannot readt property '0' of null at UpdateCourriel.
I'm not really good with javascript so any help is appreciated.
Here are both scripts that are called:
VideCourriel = function () {
window.Xrm.Page.getAttribute('new_courriel').setSubmitMode('always');
window.Xrm.Page.getAttribute("new_courriel").setValue(null);
};
UpdateCourriel = function () {
var contactid = window.Xrm.Page.getAttribute('responsiblecontactid').getValue()[0].id;
if (contactid !== null) {
var contact = $.odata.getOne("/ContactSet(guid'" + contactid + "')/EMailAddress1");
var courriel = "";
if (typeof contact !== 'undefined' && contact !== null && typeof contact.EMailAddress1 !== 'undefined') {
courriel = contact.EMailAddress1;
}
window.Xrm.Page.getAttribute('new_courriel').setSubmitMode('always');
window.Xrm.Page.getAttribute('new_courriel').setValue(courriel);
}
};
Thanks!
*This post is locked for comments