Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Error with field's customized event Field: window Event:onload

Posted on by Microsoft Employee

I am attempting to hide certain tabs on an Order form based on a field called 'department'. I will attach a screenshot of the error and my code.

function Form_OnLoad()
{
    setDepartmentDisabled();
    setFormState();
}

function setDepartmentDisabled()
{
    var department = Xrm.Page.ui.controls.get('aai_department');
    if (department != null && department != 'undefined')
    {
        var formType = Xrm.Page.ui.getFormType();

        switch (formType)
        {
            case FORM_TYPE_CREATE:
                department.setDisabled(false);
                break;

            default:
                var value = getSelectedOptionValue(department.getAttribute().getName());
                switch (value)
                {
                    case 100000000:
                    case 100000001:
                    case 100000002:
                    case 100000003:
                        department.setDisabled(true);
                        break;

                    default:
                        break;
                }
                break;
        }
    }
}

function setFormState()
{
    var value = getSelectedOptionValue('aai_department');
    switch (value)
    {
        case 100000000: //Underwriting
        case 100000001: //Asset Management
            setVisible(TAB_ZONING, false, requiredFieldsZoning);
            setVisible(TAB_UNDERWRITING_AND_ASSETMANAGEMENT, true, requiredFieldsUnderwritingAssetManagement);
            //setVisible(SECTION_CLOSING, false, requiredFieldsClosing);
            Xrm.Page.getAttribute("new_oversight").setRequiredLevel("required");
            Xrm.Page.getAttribute("new_underwriter").setRequiredLevel("none");
            Xrm.Page.getAttribute("new_analyst").setRequiredLevel("required");
            Xrm.Page.getAttribute("aai_kickoff").setRequiredLevel("none");
            Xrm.Page.getAttribute("aai_duedate").setRequiredLevel("none");
            Xrm.Page.getAttribute("aai_deliverydate").setRequiredLevel("none");
            break;

        case 100000002: //Zoning
            setVisible(TAB_ZONING, true, requiredFieldsZoning);
            setVisible(TAB_UNDERWRITING_AND_ASSETMANAGEMENT, false, requiredFieldsUnderwritingAssetManagement);
            //setVisible(SECTION_CLOSING, false, requiredFieldsClosing);
            Xrm.Page.getAttribute("new_oversight").setRequiredLevel("none");
            Xrm.Page.getAttribute("new_underwriter").setRequiredLevel("none");
            Xrm.Page.getAttribute("new_analyst").setRequiredLevel("required");
            Xrm.Page.getAttribute("aai_kickoff").setRequiredLevel("required");
            Xrm.Page.getAttribute("aai_duedate").setRequiredLevel("required");
            Xrm.Page.getAttribute("aai_deliverydate").setRequiredLevel("none");
            break;

        case 100000003: //Closing
            setVisible(TAB_ZONING, false, requiredFieldsZoning);
            setVisible(TAB_UNDERWRITING_AND_ASSETMANAGEMENT, true, requiredFieldsUnderwritingAssetManagement);
            //setVisible(SECTION_CLOSING, false, requiredFieldsClosing);
            Xrm.Page.getAttribute("new_oversight").setRequiredLevel("required");
            Xrm.Page.getAttribute("new_underwriter").setRequiredLevel("required");
            Xrm.Page.getAttribute("new_analyst").setRequiredLevel("none");
            Xrm.Page.getAttribute("aai_kickoff").setRequiredLevel("required");
            Xrm.Page.getAttribute("aai_duedate").setRequiredLevel("required");
            Xrm.Page.getAttribute("aai_deliverydate").setRequiredLevel("none");
            break;


        default:
            setVisible(TAB_ZONING, false, requiredFieldsZoning);
            setVisible(TAB_UNDERWRITING_AND_ASSETMANAGEMENT, false, requiredFieldsUnderwritingAssetManagement);
            //setVisible(SECTION_CLOSING, false, requiredFieldsClosing);
            break;
    }
}

function setVisible(id, value, requiredFields)
{
    if (id != '')
    {
        var tab = Xrm.Page.ui.tabs.get(id);
        tab.setVisible(value);
}


04406.Capture.PNG

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Error with field's customized event Field: window Event:onload

    Yes, I left the global var out. It is set at the top of the .js file.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Error with field's customized event Field: window Event:onload

    var FORM_TYPE_CREATE = 1;

    function setDepartmentDisabled()
    {
        var department = Xrm.Page.ui.controls.get('aai_department');
        if (department != null && department != 'undefined')
        {
            var formType = Xrm.Page.ui.getFormType();
    
            switch (formType)
            {
                case FORM_TYPE_CREATE:
                    department.setDisabled(false);
                    break;
    
                default:
                    var value = getSelectedOptionValue(department.getAttribute().getName());
                    switch (value)
                    {
                        case 100000000:
                        case 100000001:
                        case 100000002:
                        case 100000003:
                            department.setDisabled(true);
                            break;
    
                        default:
                            break;
                    }
                    break;
            }
        }
    }
    



  • Suggested answer
    Haansi Profile Picture
    Haansi 1,431 on at
    RE: Error with field's customized event Field: window Event:onload

    [quote user="Brandon.Herring"]FORM_TYPE_CREATE[/quote]

    Not sure about it ? Is it something you have declared somewhere in code ?

    [quote user="Brandon.Herring"]getSelectedOptionValue(department.getAttribute().getName());

                   switch (value)[/quote]

    Apologies it may be my mobile display but top switch and inner switch looks not correctly formated.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Error with field's customized event Field: window Event:onload

    I have also removed the code all together, saved everything, and published the form without any event handlers and I still have the issue.

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans