Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

FormCheckboxControl.checked(true) is not reflected on UI

(1) ShareShare
ReportReport
Posted on by 131
Hi everyone, I have a question regarding the customization in Dynamics 365 Finance and Operations. I customize some fields on the DirPartyQuickCreateForm. The fields are the customized fields that I created in CustTable. Two of them are the checkbox control. 
 
//
 
In my code which is written in the DirPartyQuickCreateForm_OnInitialized(), the /e-Invoice/ checkbox is represented with eInvCB, while /Consolidate E-Invoice/ is represented as consoCB. I tried to set eInvCB.autoDeclaration(true); eInvCB.checked(true) and same goes for the consoCB variable. When I debugged, I could see the value of my eInvCB was equal to 1, but the UI still showed unchecked.

For this issue, I tried to set eInvCB.value(1) but the UI remains unchanged. So, I would like to know if there is any way to check the checkbox when the form is initialized.

I appreciate any suggestions and guidance provided.

Thanks and regards,
Yue 
  • Suggested answer
    Navneeth Nagrajan Profile Picture
    1,452 Super User 2025 Season 1 on at
    FormCheckboxControl.checked(true) is not reflected on UI
    Hi,
     
    As Martin mentioned, looks like your control is bounded to the form data source. You need to first retrieve the form DataSource buffer and then retrieve the FormCheckboxControl buffer through the formDataSource buffer. 
     
    1. Sample code correction.
     
     
     
    final class DirPartyQuickCreateFrom_Form_Handler
    {
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        [FormEventHandler(formStr(DirPartyQuickCreateForm), FormEventType::Initialized)]
        public static void DirPartyQuickCreateForm_OnInitialized(xFormRun sender, FormEventArgs e)
        {
            ads_ConsoEInvoiceParameters consoParameters;
            CustTable _custTable;
       
            FormCheckBoxControl einvCB = sender.design().controlName("<einvCBControlName");
    
    //strFmt("%1_%2", formControlStr(DirPartyQuickCreateForm, DynamicDetail), fieldStr(CustTable, ads_EInvCheckbox)));
    
            //Modification
            FormCheckBoxControl consoCB = sender.design().controlName("<consolidateeinvoicecontrolname>");
    
    //strFmt("%1_%2", formControlStr(DirPartyQuickCreateForm, DynamicDetail),
    // fieldStr(CustTable, ads_ConsolidateEInvCheckbox))) as FormCheckBoxControl;
    
            FormStringControl tin = sender.design().controlName(strFmt("%1_%2", formControlStr(DirPartyQuickCreateForm, DynamicDetail), fieldStr(CustTable, ads_TIN)));
    
            FormStringControl ic = sender.design().controlName(strFmt("%1_%2", formControlStr(DirPartyQuickCreateForm, DynamicDetail), fieldStr(CustTable, IdentificationNumber)));
    
            ic.label("Business registration/ identification/ passport number ");
            consoCB.autoDeclaration(true);
            einvCB.autoDeclaration(true);
            //einvCB.value(enum2int(NoYes::Yes));
            _custTable.ads_EInvCheckbox = 1;
            
            //Remove this and add a code in the find() method on the table ads_ConsoEInvoiceParameters
            select * from consoParameters;
    
            if(consoParameters.ads_ConsolidateEInvCheckbox == 1)
            {
                consoCB.checked(true);
            }
            else
            {
                consoCB.checked(false);
                tin.mandatory(true);
                ic.mandatory(true);
            }
        }
    
    }
    Tested the sample code on my sample development machine and this works.
     
    2.  Also, eliminate the statement from the OnInitialized event handler method. Instead add a find() method and add the select * from consoParamters in that find() method of the table ads_ConsoEInvoiceParameters. 
             select * from consoParamters 
     
    Adopt a similar approach for the 
     
    Thanks,
    Navneeth Nagrajan
    If this helped, please mark it as "Verified" for others facing the same issue
     
  • Verified answer
    Yue Zhen Profile Picture
    131 on at
    FormCheckboxControl.checked(true) is not reflected on UI
    I made it! I found out that I should use CoC to extend the data source and override its initValue() method to set the checkbox value default to 1.
  • Yue Zhen Profile Picture
    131 on at
    FormCheckboxControl.checked(true) is not reflected on UI
    final class DirPartyQuickCreateFrom_Form_Handler
    {
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        [FormEventHandler(formStr(DirPartyQuickCreateForm), FormEventType::Initialized)]
        public static void DirPartyQuickCreateForm_OnInitialized(xFormRun sender, FormEventArgs e)
        {
            ads_ConsoEInvoiceParameters consoParameters;
            CustTable _custTable;
            
            FormCheckBoxControl einvCB = sender.design().controlName(strFmt("%1_%2", formControlStr(DirPartyQuickCreateForm, DynamicDetail), fieldStr(CustTable, ads_EInvCheckbox)));
    
            FormCheckBoxControl consoCB = sender.design().controlName(strFmt("%1_%2", formControlStr(DirPartyQuickCreateForm, DynamicDetail), fieldStr(CustTable, ads_ConsolidateEInvCheckbox)));
    
            FormStringControl tin = sender.design().controlName(strFmt("%1_%2", formControlStr(DirPartyQuickCreateForm, DynamicDetail), fieldStr(CustTable, ads_TIN)));
    
            FormStringControl ic = sender.design().controlName(strFmt("%1_%2", formControlStr(DirPartyQuickCreateForm, DynamicDetail), fieldStr(CustTable, IdentificationNumber)));
    
            ic.label("Business registration/ identification/ passport number ");
            consoCB.autoDeclaration(true);
            einvCB.autoDeclaration(true);
            //einvCB.value(enum2int(NoYes::Yes));
            _custTable.ads_EInvCheckbox = 1;
            
            select * from consoParameters;
    
            if(consoParameters.ads_ConsolidateEInvCheckbox == 1)
            {
                consoCB.checked(true);
            }
            else
            {
                consoCB.checked(false);
                tin.mandatory(true);
                ic.mandatory(true);
            }
        }
    
    }
    I tried to create the new customer record and I found that the checkbox is still showing unchecked and the value stored in the table in SSMS is 0. I tried to write _custTable.ads_EInvCheckbox = true or 
    FormCheckBoxControl einvCB = sender.design().controlName(strFmt("%1_%2", formControlStr(DirPartyQuickCreateForm, DynamicDetail), fieldStr(CustTable, ads_EInvCheckbox))) as FormCheckBoxControl;
    einvCB.value(enum2int(NoYes::Yes));

    or

    einvCB.checked(1);

    but all of them are not working for my case. I did tried to set allowEdit(false), it worked.
  • Martin Dráb Profile Picture
    231,837 Most Valuable Professional on at
    FormCheckboxControl.checked(true) is not reflected on UI
    If it's bound to a data source, set a value of the datasource field (e.g. custTable.MyField = true) instead of setting the value of the control itself.
  • Suggested answer
    Waed Ayyad Profile Picture
    7,840 Super User 2025 Season 1 on at
    FormCheckboxControl.checked(true) is not reflected on UI
    Hi,
     
    You can try this code :
     
    
    FormCheckBoxControl yourCheckBox = sender.design().controlName(formControlStr(YourFormName,YourControlName)) as FormCheckBoxControl;
    
    yourCheckBox.value(enum2int(NoYes::No));
     
    Thanks,
    Waed Ayyad
    If this helped, please mark it as "Verified" for others facing the same issue
     
  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    3,622 Moderator on at
    FormCheckboxControl.checked(true) is not reflected on UI
    Did you try run method something like this? Try defaulting with 1 instead true like below.
     
    eInvCB.checked(1);
  • Layan Jwei Profile Picture
    7,722 Super User 2025 Season 1 on at
    FormCheckboxControl.checked(true) is not reflected on UI
    Hi Yue,

    Do you mean when you first open the form, the flag appear as false but when debugging they appear as true?

    Also please share with us your code

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... 293,001 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,837 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans