Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

JS on OnLoad form error

Posted on by Microsoft Employee

Hello,

I wrote a very easy JS that works on OnLoad of the Form, but I have an "TypeError: Cannot read property 'Initialize' of undefined at eval (eval at RunHandlerInternal" error.

If anyone of you might help, it would be amazing!

Script si below. 

// JavaScript Document

function showHide(){

var queryType = Xrm.Page.getAttribute("srm_reviewtype").getValue();
if(queryType != null){

if(queryType == 165780000){
Xrm.Page.ui.tabs.get("GeneralTab").sections.get("REVIEW_INFORMATION").setVisible(true);
Xrm.Page.ui.tabs.get("GeneralTab").sections.get("FINANCIAL_STATUS_CHECK").setVisible(true);
Xrm.Page.ui.tabs.get("GeneralTab").sections.get("PERFORMANCE_REVIEW").setVisible(false);
Xrm.Page.ui.tabs.get("GeneralTab").sections.get("FEEDBACK_BY").setVisible(false);
Xrm.Page.ui.tabs.get("GeneralTab").sections.get("ACTIVITIES").setVisible(false);
}

else if(queryType == 165780001){
Xrm.Page.ui.tabs.get("GeneralTab").sections.get("REVIEW_INFORMATION").setVisible(true);
Xrm.Page.ui.tabs.get("GeneralTab").sections.get("FINANCIAL_STATUS_CHECK").setVisible(false);
Xrm.Page.ui.tabs.get("GeneralTab").sections.get("PERFORMANCE_REVIEW").setVisible(true);
Xrm.Page.ui.tabs.get("GeneralTab").sections.get("FEEDBACK_BY").setVisible(true);
Xrm.Page.ui.tabs.get("GeneralTab").sections.get("ACTIVITIES").setVisible(true);
}
}

else
{
Xrm.Page.ui.tabs.get("GeneralTab").setVisible(true);
}
}

*This post is locked for comments

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: JS on OnLoad form error

    After all I didn't find a solution. I had to create a new custom entity and then it worked well.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: JS on OnLoad form error

    Hello

    community.dynamics.com/.../194344

    Hope this link may help you!

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: JS on OnLoad form error

    I saw this once before and removing the javascript from the form and adding it back, oddly enough, seemed to resolve it.

  • abhishek_255 Profile Picture
    abhishek_255 1,612 on at
    RE: JS on OnLoad form error

    You can try commenting the function body and put an alert just to validate any issue while function call. In case alert appears then there must be something wrong in your function body. You can use developer tools and debug your java script at runtime.

    Otherwise validate the container (web resource) and function name.

    Best Regards,

    Abhishek

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: JS on OnLoad form error

    Hi Dominik,

    I don't have enough details to know if you can use it, but you can assess to create "Business Rules" in your form to Show/hide fields instead of JS.

    A small "trick" is that, if you have a section "not visible" by default, and then you have a Business rules to show a field in the section, that section will appear, not only the field.

    Hope this helps.

  • VermaNitin Profile Picture
    VermaNitin 455 on at
    RE: JS on OnLoad form error

    Hi Dominik,

    At the first sight it seems that the issue does not belong to your code.

    Try clearing the cache or try using another browser.

    Is the error shown in an alert on the form? If not then you can just neglect it or at the last you may contact Microsoft support.

    Hope it helps!

    Many thanks,

    Nitin Verma

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: JS on OnLoad form error

    Hi Dominik,

     is it all the code you have in that web resource? I don't see any errors either.. besides, the error looks s a bit unusual to say the least.

  • Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: JS on OnLoad form error

    Hi Dominik,

    I don't think that error has anything to do with your onLoad code. Your code looks fine.

    You can put a breakpoint in your code and see if it reaches your code, or it might be a CRM error.

    Can you try running your site in InPrivate mode and see if you get the same error?

    It is possibly some caching issue or null value issue.

    I am attaching a function that you can use to show/hide sections in your code. Makes it simpler to write some of the code and prevent issues:

    // Set Section Visibility

    setSectionVisibleState("GeneralTab", "REVIEW_INFORMATION", true);

    function setSectionVisibleState(tabName, sectionName, isVisible)

    {

       Xrm.Page.ui.tabs.get(tabName).sections.get(sectionName).setVisible(isVisible);

    }

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans