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 :
Finance | Project Operations, Human Resources, ...
Answered

FormCheckboxControl.checked(true) is not reflected on UI

(1) ShareShare
ReportReport
Posted on by 147
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 
I have the same question (0)
  • Layan Jwei Profile Picture
    8,112 Super User 2025 Season 2 on at
    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
  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at
    Did you try run method something like this? Try defaulting with 1 instead true like below.
     
    eInvCB.checked(1);
  • Suggested answer
    Waed Ayyad Profile Picture
    9,039 Super User 2025 Season 2 on at
    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
     
  • Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at
    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.
  • Yue Zhen Profile Picture
    147 on at
    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.
  • Verified answer
    Yue Zhen Profile Picture
    147 on at
    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.
  • Suggested answer
    Navneeth Nagrajan Profile Picture
    2,430 Super User 2025 Season 2 on at
    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
     

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 611 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 529 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans