Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Error onload javascript - "There was an error with this field's customized event."

(0) ShareShare
ReportReport
Posted on by 1,324

I've added a web resource to opportunities to set a blank default value for a two option field on opportunities. I get this error message, and after clicking OK, the default value is correctly removed. Below is the code (used from https://www.magnetismsolutions.com/blog/11-09-19/No_Default_Value_on_Two_Options_Field_Dynamics_CRM_2011.aspx)

There was an error with this field's customized event.

Field:window

Event:onload

error:undefined 

// Set the value of a Two Options / Radio Button to null by default

function setTwoOptionNull(twoOption) {

    var isCreateForm = Xrm.Page.ui.getFormType() == 1;

    var twoOptionField = Xrm.Page.getAttribute("new_changeorder");

    var twoOptionValue = twoOptionField.getValue();

    if (isCreateForm) {

        twoOptionField.setValue(null); // set the value to null on create

        twoOptionField.setSubmitMode("always"); // required to store the null value

 

        // Needed for when you're using a Required 2 Options field - UNSUPPORTED

        // The first Radio Button must be False, and the Default Value (is by default)

        document.getElementById("rad_" + twoOption + "1").onclick = function () { 

            // Change the Value, then set it back to trick CRM into thinking its changed

            if (twoOptionValue == false) {

                twoOptionField.setValue(true);

                twoOptionField.setValue(false);

            }

        }

    }

}



*This post is locked for comments

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 Moderator on at
    RE: Error onload javascript - "There was an error with this field's customized event."

    Hi,

    As mentioned above, the code you are using is unspported and will not work.

    If you just want to set the value blank then you can use

    ==========

    Xrm.Page.getAttribute("creditonhold").setValue(null);

    Xrm.Page.getAttribute("creditonhold").setSubmitMode("always");

    ========

    Hope this helps.

  • Verified answer
    gdas Profile Picture
    gdas 50,089 Moderator on at
    RE: Error onload javascript - "There was an error with this field's customized event."

    Hi ,

    As Aric mentioned this is not supported code , two option is only for  true /false or 0/1 value . If you really need any additional value please create another normal optionset field where you can easily control this by supported ways.

    Here is the sample- how to add ,remove , clear optionset value from normal optionset.

    function OnloadOptionSetAddRemove() {
        var optionSet = Xrm.Page.ui.controls.get("new_changeorder");
        var optionSetValues = optionSet.getAttribute().getOptions();
        optionSet.clearOptions();
        optionSetValues.forEach(function (element) {      
                optionSet.addOption(element); //For Add option set    
                optionSet.addOption(element); //For Remove optionset 
        });
    }


    Please note your customization may not be work in future release of dynamics CRM , so dont go for unsupported way use only supported JavaScript for customization as per MS recommendation. 

  • Suggested answer
    Abby Kong Profile Picture
    Abby Kong 6 on at
    RE: Error onload javascript - "There was an error with this field's customized event."

    Please see below image of "Two Option" with display "Two Radio Buttons" comparison of CRM2011 and Dynamics 365.

    TwoOptionsRadioButton.png

      document.getElementById("rad_" + twoOption + "1").onclick

    This line looking for id "rad_xxx_1" would only work with DOM on the left. As you can see in the image, rendering is completely different using 'ms-crm-inline-edit' div in the newer version, rather than input type radio.

    Can you check how this is rendered in CRM2015?

    I think it's best to avoid unsupported DOM manipulation, as no one knows what might change with future upgrades.

  • Aric Levin Profile Picture
    Aric Levin 30,188 Moderator on at
    RE: Error onload javascript - "There was an error with this field's customized event."

    Hi,

    As you mention in your code, it is unsupported. It was written for CRM 2011, and very possibly this manipulation of the DOM in 2015 is causing issues.

    If that's not the case, I would add the debugger statement inside my function call and step through the code to find exactly where there is an error to assist with troubleshooting.

    Hope this helps.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans