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 :
Customer experience | Sales, Customer Insights,...
Answered

onChange Event Not Triggering for Boolean Fields Regardless of Control

(0) ShareShare
ReportReport
Posted on by 283

I have a form with multiple boolean fields. When one of the fields is marked "True" I want certain corresponding fields to be shown.

I have onChange events set for these boolean fields to call the function "REP.Report.showCorrespondingField". When I change the value of the fields, the onChange event is not triggered and the function is not called, regardless of which control is used - toggle, checkbox or list. However, I have a couple integer fields elsewhere on the form where the onChange event is being triggered correctly.

Please help me figure out why these fields are triggering onChange! TIA!

var REP = REP || {};
REP.Report = REP.Report || {};
let formContext = null;

(function() {
'use strict';
REP.Report.onLoad = function(executionContext) {
    formContext = executionContext.getFormContext();
}

REP.Report.showCorrespondingField = function(changedField,hiddenField1,hiddenField2) {
    if(changedField === true) {
        formContext.getControl(hiddenField1).setVisible(true);
        if(hiddenField2) {
            formContext.getControl(hiddenField2).setVisible(true);
        }
    }
};

REP.Report.setTotalHours = function() {
    let primHours = formContext.getAttribute('new_q3atotalhoursprimary').getValue();
    let secHours = formContext.getAttribute('new_q3btotalhourssecondary').getValue();
    formContext.getAttribute('new_q3ctotalhours').setValue(primHours   secHours);
}
})();

pastedimage1633628656925v1.png

I have the same question (0)
  • Suggested answer
    Pradeep Rai Profile Picture
    5,489 Moderator on at

    HI,

    Have you enabled wave2 2021 ?

    Because i am also facing the same and i have enabled the wave2 2021 update. When i created the field from unified interface and added the script then onchange of Two Option function does not get triggered.

    Then i created the Two Option Field in Classic UI and then added below line on load of Script.

     formContext.getAttribute('new_twooption').addOnChange(OnChangeOfTwoOption);
    After this, onchange event started working.

    So, please try to create field from classic UI and then try the same script.
    Thanks,
    Pradeep.
    Please mark this as VERIFIED if it helps.
  • Lucas H Profile Picture
    283 on at

    Yes I have wave 2 enabled. Glad to hear I'm not going crazy!!!

    I had tried the addOnChange method as well with my current fields but got this error: "Required parameter is null or undefined: handler".

    I'll try it again in the classic UI and update soon!

  • Lucas H Profile Picture
    283 on at

    I created a test field in the Classic UI, added it to the form and added the addOnChange line but am still getting the "Required parameter is null or undefined: handler" error.

    However, my onChange function has parameters that I want to pass. Could that affect it?

    formContext.getAttribute('new_reptest').addOnChange(REP.Report.showCorrespondingField(executionContext,'new_reptest','new_q1ahelpedlocalchurchesinfo',0));

  • Verified answer
    Pradeep Rai Profile Picture
    5,489 Moderator on at

    Hi,

    It means now you are able to call the JavaScript function but getting some error after call.

    Please try code in below way:

    function onLoad()
    {
    
    formContext.getAttribute('new_reptest').addOnChange(callback);
    }
    
    function callback(executionContext)
    {
    REP.Report.showCorrespondingField(executionContext,'new_reptest','new_q1ahelpedlocalchurchesinfo',0);
    }

    In onload function just specify the function name and by default the execution context parameter will be passed to callback function.
    Now on callback function call required function.

    Happy coding. 

    Thanks,
    Pradeep.

    Please mark this as VERIFIED if it helps.

  • Lucas H Profile Picture
    283 on at

    UPDATE: It looks like the extra parameters have to be inside of quotations... that does the trick!

    Hey Pradeep! I was able to get this solution to work, but it looks like the issue with the onChange not working for booleans has been fixed.

    However, the onChange event is now not firing AT ALL when I try to pass parameters, with and without passing the execution context first:

    pastedimage1635876081357v1.png

    Any thoughts on this?

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 83 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans