Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Upgraded from CRM 4.0 to 2016 (on-prem) ... now get script errors in Contacts

Posted on by 35

Particularly in Contacts ... when in "CONTACT" 'view' things seem to be okay, but when changing to "CONTACT:Information" in any contact, the script errors start (even when just changing to this view).

Script Error

One of the scripts for this record has caused an error. For more details, download the log file.
ReferenceError: 'crmForm' is undefined at Form_onload (crm2016.domain.local/.../Contact_main_library.js)

Click OK. All good. Changes can be made to contacts, and mostly there are no issues. Create a new contact, and get the same script error again. Switch from CONTACT to CONTACT:Information view ... and script error appears.

The downloaded log file contains:

ReferenceError: 'crmForm' is undefined
at Form_onload (crm2016.domain.local/.../Contact_main_library.js)
at eval code (eval code:1:1)
at RunHandlerInternal (crm2016.domain.local/.../ClientApiWrapper.aspx)
at RunHandlers (crm2016.domain.local/.../ClientApiWrapper.aspx)
at OnScriptTagLoaded (crm2016.domain.local/.../ClientApiWrapper.aspx)
at Anonymous function (crm2016.domain.local/.../ClientApiWrapper.aspx)

Thanks,

Jason

*This post is locked for comments

  • Suggested answer
    Jay26Cee Profile Picture
    Jay26Cee 35 on at
    RE: Upgraded from CRM 4.0 to 2016 (on-prem) ... now get script errors in Contacts

    Hi Arun ... I am going to mark this response as the answer.

    I have been informed that the script for Company:Information is now no longer required too. So, this means we can drop the script on form load. I did find another method (likely the preferred method) for inserting a Google Map via a Web Resource, so will look into that if needed.

    Thanks for your help.

    Jason

  • Jay26Cee Profile Picture
    Jay26Cee 35 on at
    RE: Upgraded from CRM 4.0 to 2016 (on-prem) ... now get script errors in Contacts

    Hi Ravi

    Thanks for your suggestion. I will look into this. For the time being though, I am just trying to please the users by suppressing these errors.

    Regards,

    Jason

  • Jay26Cee Profile Picture
    Jay26Cee 35 on at
    RE: Upgraded from CRM 4.0 to 2016 (on-prem) ... now get script errors in Contacts

    Thanks Arun.

    It was the "Publish" part that I missed - although I needed to do this twice for some reason. So, script error resolved for this form.

    I do have another script for Company:Information form, and applied the same logic here too ... but the end result is still a script error, albeit a slightly different one.

    Error:

    Script Error

    One of the scripts for this record has caused an error. For more details, download the log file.

    TypeError: Unable to get property 'setSrc' of undefined or null reference at Form_onload (https://<FQDN>/<instance>/%7B636712172480000112%7D/WebResources/Account_main_library.js?ver=1865024846:22:7)

    Bold below are the areas of change...

    Before script change:

    function IFRAME_Financials_onload()
    {

    }
    function IFRAME_WebSite_onload()
    {

    }
    function IFRAME_Map_onload()
    {

    }
    function Form_onload()
    {
    // Load yahoo finance ticker link
    {
    var TickerValue = crmForm.all.tickersymbol.DataValue;
    var YahooURL ="uk.finance.yahoo.com/q"+ TickerValue;

    if (YahooURL != null)
    {
    crmForm.all.IFRAME_Financials.src = YahooURL;
    }
    }

    // Load web site URL
    {
    var AccountURL = crmForm.all.websiteurl.DataValue;
    if (AccountURL != null)
    {
    crmForm.all.IFRAME_WebSite.src = AccountURL;
    }
    }

    // Load Map URL
    {
    var AccountStreet1 = crmForm.all.address1_line1.DataValue;
    var AccountStreet2 = crmForm.all.address1_line2.DataValue;
    var AccountCity = crmForm.all.address1_city.DataValue;
    var AccountState = crmForm.all.address1_stateorprovince.DataValue;
    var AccountZip = crmForm.all.address1_postalcode.DataValue;
    var AccountCntry = crmForm.all.address1_country.DataValue;

    var MapURL = "maps.google.co.uk/maps;q=" + AccountStreet1 + " " + AccountCity +" " + AccountZip + " " + AccountCntry;

    if (MapURL != null)
    {
    crmForm.all.IFRAME_Map.src = MapURL;
    }
    }
    }

    After script change:

    function IFRAME_Financials_onload()
    {

    }
    function IFRAME_WebSite_onload()
    {

    }
    function IFRAME_Map_onload()
    {

    }
    function Form_onload()
    {
    // Load yahoo finance ticker link
    {
    var TickerValue = Xrm.Page.getAttribute("tickersymbol").getValue();
    var YahooURL ="uk.finance.yahoo.com/q"+ TickerValue;

    if (YahooURL != null)
    {
    Xrm.Page.getControl('IFRAME_Financials').setSrc(YahooURL);
    }
    }

    // Load web site URL
    {
    var AccountURL = Xrm.Page.getAttribute("websiteurl").getValue();
    if (AccountURL != null)
    {
    Xrm.Page.getControl('IFRAME_WebSite').setSrc(AccountURL);
    }
    }

    // Load Map URL
    {
    var AccountStreet1 = Xrm.Page.getAttribute("address1_line1").getValue();
    var AccountStreet2 = Xrm.Page.getAttribute("address1_line2").getValue();
    var AccountCity = Xrm.Page.getAttribute("address1_city").getValue();
    var AccountState = Xrm.Page.getAttribute("address1_stateorprovince").getValue();
    var AccountZip = Xrm.Page.getAttribute("address1_postalcode").getValue();
    var AccountCntry = Xrm.Page.getAttribute("address1_country").getValue();

    var MapURL = "maps.google.co.uk/maps;q=" + AccountStreet1 + " " + AccountCity +" " + AccountZip + " " + AccountCntry;

    if (MapURL != null)
    {
    Xrm.Page.getControl('IFRAME_Map').setSrc(MapURL);
    }
    }
    }

    It is interesting that the script error references "setSrc" yet the same setSrc was used - without error - in the Contact:Information script. Is there something wrong code or syntax in the variables in this new JS?

    Also, I ran the Dynamics 365 V9 Javascript Validator in XrmToolBox, and it is returning the following:

    Method Xrm.Page must be replace with ExecutionContext.getFormContext

    This is mentioned for every line in both this Account_main_library.js and Contact_main_library.js scripts ... can you advise on this?

    Should I just replace the Xrm.Page references in the lines with ExecutionContext.getFormContext?

    Example: 

    var AccountCntry = Xrm.Page.getAttribute("address1_country").getValue();

    and 

    Xrm.Page.getControl('IFRAME_Map').setSrc(MapURL);

    ...become...

    var AccountCntry = ExecutionContext.getFormContext.getAttribute("address1_country").getValue();

    and 

    ExecutionContext.getFormContext.getControl('IFRAME_Map').setSrc(MapURL);

    Thanks for your help.

    J

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Upgraded from CRM 4.0 to 2016 (on-prem) ... now get script errors in Contacts

    Hi,

    In CRM 4.0, all the entities used to have the system library with the entity name, in this case it is "Contact_main_library.js". With the upgrade to 2011>> 2013 and so on, these script are now internaly managed by CRM i.e. does not appear in the form editor. In my opinion, you shouldn't be using the old form and insted use the new form (it should say in descripton something like The default updated form).

    If you ado not have the fields and layout on your new form then you can manually create that. I remember in 2011/ 2013 there used to be a way in the form editor to merge the records (ribbon button named "merge button)". This is some you can try. But please create a copy of your Contact Form before trying.  

    Hope this helps.

  • Verified answer
    Arun Vinoth Profile Picture
    Arun Vinoth 11,613 on at
    RE: Upgraded from CRM 4.0 to 2016 (on-prem) ... now get script errors in Contacts

    It means you have 2 main forms for contact entity. In only one form - Information you have an IFRAME, the source url for that iframe is set dynamically on form load using this script.

    Did you publish the customizations after you edit the file? Make sure you follow all the steps religiously from the above blog post I shared. It will solve your problem.

  • Jay26Cee Profile Picture
    Jay26Cee 35 on at
    RE: Upgraded from CRM 4.0 to 2016 (on-prem) ... now get script errors in Contacts

    Hi,

    The changes suggested to the script had no effect.

    Looking into this a little more has made me even more confused ... for 2 reasons:

    1. When I edited the 'script' called Contact_main_library.js via the Form Editor in CRM, I still got the same error. This implies that the issue is not with that edited change as there is no longer a reference to "crmForm" yet the error message still references this.

    Also, I tried to look for Contact_main_library.js as a script file on the server, but none were found. The closest was a script file called Contact_main_system_library.js ... and editing this script had no reference to "crmForm"!

    I searched on the server for ALL .js script files starting with "Contract" and none have a reference to "crmForm".

    2. The other confusing this is that the default Contact form that loads when you click on "New Contact" loads a form called "Contact" which is a Main form type. Looking at the Form properties for this reveals no Form Libraries and no Event Handlers being referenced. This probably explains why this Contact form does not generate any script errors.

    It is only when you click on the CONTACT drop-down and select the form called "Information" to load that form up does the error appear. And, it is that form - called "Information" and also a Main form type - that has the Form Library and Event Handler called Contact_main_library.js.

    So, I guess my question here is ...... what is this script and why is it needed?

    Regards,

    Jason

  • Verified answer
    Arun Vinoth Profile Picture
    Arun Vinoth 11,613 on at
    RE: Upgraded from CRM 4.0 to 2016 (on-prem) ... now get script errors in Contacts

    Not really. You can do it yourself. Pls follow the below guide to make changes to js web resource from form editor.

    [View:https://dynamicscrmpros.com/getting-started-with-javascript-form-scripting-for-microsoft-dynamics-crm-2011/:750:50]

    Look for your existing js file, edit it in browser (take a backup if you want) or copy the content to favorite text editor like Notepad++

    Replace the below lines

    var SocialURL = crmForm.all.new_profnetworkpage.DataValue;
    
    if (SocialURL != null)
    
    {
    
    crmForm.all.IFRAME_PNetwork.src = SocialURL;
    
    }

    with these lines:

    var socialURL = Xrm.Page.getAttribute("new_profnetworkpage").getValue();
    
    if (socialURL != null)
    
    {
    
    Xrm.Page.getControl('IFRAME_PNetwork').setSrc(socialURL);
    
    }
    

  • Jay26Cee Profile Picture
    Jay26Cee 35 on at
    RE: Upgraded from CRM 4.0 to 2016 (on-prem) ... now get script errors in Contacts

    Hi Arun,

    Can you offer some guidance on how to make the changes?

    Do these changes require special tools to make the changes?

    I'd like to know whether your recommendation is that if this is not something one has done before, then should it be left to the 'professionals' or is it simple enough with some guidance from someone like yourself?

    I ask I the link you provide seems to shed light on someone else's issue, but I am still lost as to where this change is applied - and how.

    Thanks.

    Jason

  • Jay26Cee Profile Picture
    Jay26Cee 35 on at
    RE: Upgraded from CRM 4.0 to 2016 (on-prem) ... now get script errors in Contacts

    Thanks Shidin for you response. I have managed to get XrmToolBox up and running, installed the plugin you suggested.

    The Retrieve JScript Webresources ... Found 5 JScript Webresources.

    The Scan to validate resulted in 0 (zero) issues.

    I am going to take a look at Arun's suggestion above ... but I am starting to delve into some uncharted territory with these scripts!

  • Suggested answer
    Shidin Haridas Profile Picture
    Shidin Haridas 3,497 on at
    RE: Upgraded from CRM 4.0 to 2016 (on-prem) ... now get script errors in Contacts

    crmForm (used in v4.0) was the older equivalent of Xrm.Page, which is also getting depreciated now!

    Easiest way for you to find out all the legacy JavaScript code would be to use the 'Dynamics 365 v9 Javascript Validator' tool from the XrmToolbox

    This will scan all your custom script files and notify you of all the deprecated methods.

    Cheers,

    Shidin

    If my answer helps you, please mark it as verified.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans