
I am getting the following error, "unable to get property Initialize of undefined or null reference" when my form loads for some reason. The script that I am trying to have run only on change of a field, not on load is:
function CommunicationTypeCommercialOnChange()
{
var CommunicationType = Xrm.Page.getAttribute("nhs_communicationtype").getText();
var RecordType = Xrm.Page.getAttribute("nhs_recordtype").getText();
if ((RecordType == null || RecordType =='undefined' || RecordType =='') && (CommunicationType == null || CommunicationType =='undefined' || CommunicationType ==''))
{
Xrm.Page.getAttribute("nhs_returnaddressaddress1").setValue(null);
Xrm.Page.getAttribute("nhs_returnaddressaddress2").setValue(null);
Xrm.Page.getAttribute("nhs_returnaddresscity").setValue(null);
Xrm.Page.getAttribute("nhs_returnaddressstate").setValue(null);
Xrm.Page.getAttribute("nhs_returnaddresszip").setValue(null);
}
else if ((RecordType == "Commercial") && (CommunicationType == null || CommunicationType =='undefined' || CommunicationType ==''))
{
Xrm.Page.getAttribute("nhs_returnaddressaddress1").setValue(null);
Xrm.Page.getAttribute("nhs_returnaddressaddress2").setValue(null);
Xrm.Page.getAttribute("nhs_returnaddresscity").setValue(null);
Xrm.Page.getAttribute("nhs_returnaddressstate").setValue(null);
Xrm.Page.getAttribute("nhs_returnaddresszip").setValue(null);
}
else if ((RecordType == "Commercial") && (CommunicationType == "Clincal Transition"))
{
Xrm.Page.getAttribute("nhs_returnaddressaddress1").setValue('PO Box 999');
Xrm.Page.getAttribute("nhs_returnaddressaddress2").setValue(null);
Xrm.Page.getAttribute("nhs_returnaddresscity").setValue('Appleton');
Xrm.Page.getAttribute("nhs_returnaddressstate").setValue('WI');
Xrm.Page.getAttribute("nhs_returnaddresszip").setValue('54912-0999');
}
else if ((RecordType == "Commercial") && (CommunicationType != "Clincal Transition"))
{
Xrm.Page.getAttribute("nhs_returnaddressaddress1").setValue(null);
Xrm.Page.getAttribute("nhs_returnaddressaddress2").setValue(null);
Xrm.Page.getAttribute("nhs_returnaddresscity").setValue(null);
Xrm.Page.getAttribute("nhs_returnaddressstate").setValue(null);
Xrm.Page.getAttribute("nhs_returnaddresszip").setValue(null);
}
else if (RecordType != "Commercial")
{
Xrm.Page.getAttribute("nhs_returnaddressaddress1").setValue(null);
Xrm.Page.getAttribute("nhs_returnaddressaddress2").setValue(null);
Xrm.Page.getAttribute("nhs_returnaddresscity").setValue(null);
Xrm.Page.getAttribute("nhs_returnaddressstate").setValue(null);
Xrm.Page.getAttribute("nhs_returnaddresszip").setValue(null);
}
}
Is there anything that you can see why this script wouldn't work properly?
*This post is locked for comments
I have the same question (0)This is now fixed...I had the () in the event name for onchange. Removed that and the error is gone.