web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Script error "unable to get property Initialize of undefined or null reference...

(0) ShareShare
ReportReport
Posted on by 26

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)
  • Verified answer
    USA80 Profile Picture
    26 on at

    This is now fixed...I had the () in the event name for onchange.  Removed that and the error is gone.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans