Here i have two entities Branch and Store. On Branch entity there is lookup field pointing to Store entity. When lookup is loaded automatically two fields email and phone on Branch entity are need to be loaded with Store entity email and phone details. I am getting the error TypeError: Cannot read property 'sr_email' of undefined or TypeError: Cannot read property 'sr_email' of undefined. I could unable to fix this error. Below is the code.
function BranchOnLoad() {
var svc = new Mscrm_OrganizationService(null, null, true);
var _branchLookup = new Array();
_branchLookup = Xrm.Page.getAttribute("br_storeassigned").getValue();
if (_branchLookup != null) {
debugger;
var branchName = _branchLookup[0].attributes.name.value;
var fetch = '<fetch mapping="logical">' +
'<entity name="sr_stores">' +
'<attribute name="sr_storeid"/>'+
'<attribute name="sr_name"/>'+
'<attribute name="sr_email"/>' +
'<attribute name="sr_phone1"/>' +
'<order attribute="sr_name" descending="false" />' +
'<filter type="and">' +
'<condition attribute="sr_name" operator="eq" value="' + branchName + '" /> ' +
'</filter>' +
'</entity>' +
'</fetch>';
var res = svc.Fetch(fetch);
if (res[0].attributes.sr_email) {
Xrm.Page.getAttribute("br_branchemail").setValue(res[0].attributes.sr_email.value);
}
else {
return;
}
if (res[0].attributes.sr_phone1) {
Xrm.Page.getAttribute("br_branchphone").setValue(res[0].attributes.sr_phone1.value);
}
else {
return;
}
}
if (_branchLookup == null) {
Xrm.Page.getAttribute("br_branchemail").setValue(null);
Xrm.Page.getAttribute("br_branchphone").setValue(null);
}
Xrm.Page.getAttribute("br_branchemail").setSubmitMode("always");
Xrm.Page.getAttribute("br_branchphone").setSubmitMode("always");
}
*This post is locked for comments