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

Validation message calls two times on clicking checkbox

(0) ShareShare
ReportReport
Posted on by 611

Hello All,

I have created form with two data sources. I have added one checkbox and textbox which refer the datasource1 (table name : MyTable1) and also added grid which refers to Datasource2 (table Name : MyTable2). 

Then write the below code in the create method of datasource2 in the form : 

public void create(boolean _append = false)

{

    super(_append);

    this.forceWrite(true);

} 

Also added below code in the validatewrite method of datasource2 in the form : 

public boolean validateWrite()

{

    boolean ret; 

    ret = super(); 

    if(MyTable.MyField == "")

        {

            info("Some validation message");

            ret=  false;

        }        

    return ret;

} 

My issue : When I create new record in grid and do not fill the required fields, then on closing of the form or clicking on the textbox in anywhere in the form, the validation message fires properly (Display validation message one time), but when I click on any checkbox in the form ,the validation message fires two times which should come only once.

I have verified in the call stack, the validatedwrite method gets called two times on clicking the checkbox. 

Please see the below screen shots on clicking the checkbox :

Message_5F00_Checkbox.PNG

Please see the below Screen shot of clicking on the close button :

0310.Capture1.PNG

Thanks in advance.

 

I have the same question (0)
  • Verified answer
    André Arnaud de Calavon Profile Picture
    301,146 Super User 2025 Season 2 on at

    Hi Nimisha,

    You can use the debugger to find out what is causing the execution of the coding.

  • nimi Profile Picture
    611 on at

    Hi Andre,

    found that the "validatewrite" method call two times automatically from the "LeaveRecord" method of the datasource while clicking on the checkbox but it call one time while clicking on the textbox.

    I have not added any customization code in the "LeaveRecord" Method.

    public boolean leaveRecord(boolean _forceUpdate = false)

    {

       boolean ret;

       ret = super(_forceUpdate);  --- When super() calls , "ValidateWrite" calls automatically.

       return ret;

    }

  • nmaenpaa Profile Picture
    101,162 Moderator on at

    Could you perhaps share the call stack for both validateWrite calls?

  • nimi Profile Picture
    611 on at

    Below screen shots of Call stack of "LeaveRecord" and "ValidateWrite" Method :

    "LeaveRecord" method :

    LeaveRecord_5F00_Method.PNG

     "ValidateWrite" method :

    ValidateWrite_5F00_Method.PNG

  • nmaenpaa Profile Picture
    101,162 Moderator on at

    Actually I meant screenshots of both cases where validateWrite is called. Is the call stack the same in both?

  • nimi Profile Picture
    611 on at

    Yes.The call stack is same for both when clicking on the checkbox or clicking on the textbox.

  • nmaenpaa Profile Picture
    101,162 Moderator on at

    Do you have some code in the modified method of the checkbox (form control or data source field), or in modifiedField method of the table?

    By the way, in general you should not write any code if you want to make a field mandatory. Instead, set property Mandatory to Yes in the table field. Or in form data source field, in case it should not always be mandatory, but only on this form.

  • nimi Profile Picture
    611 on at

    Thanks for your reply.

    I have verified that there is not any code on the modified method of the checkbox.

    As per your suggestion , I have set mandatory = yes property of the fields on the form data source/on the table fields and I did the below cases :

    Case : 1

    1. Remove this line (this.forceWrite(true);) from the "Create" method of the data source

    2. Create new line in the grid

    3. Not pressing the CTRL+ S

    4. Then clicking on the checkbox/textbox/closing the form --- Not generate any validation message

    Case : 2

    1. Remove this line (this.forceWrite(true);) from the "Create" method of the data source

    2. Create new line in the grid

    3. Manually pressing the CTRL+ S

    4. Generate validation message one time

    5. Then clicking on the checkbox/textbox/closing the form -- Not generate any validation message

    Case : 3

    1. Added this line (this.forceWrite(true);) in the "Create" method of data source

    2. Create new line in the grid

    3. Manually pressing the CTRL+ S

    4. Generate validation message one time

    5. Then clicking on the checkbox -- Generate validation message two times

    6. OR clicking on the textbox/closing the form -- Generate validation message one time

  • nimi Profile Picture
    611 on at

    Please support/guide me to resolve this issue.

  • André Arnaud de Calavon Profile Picture
    301,146 Super User 2025 Season 2 on at

    Hi Nimisha,

    You are talking about any checkbox. What checkboxes do you have on the form? Do they belong to datasource 1 or 2? Or are they unbound checkboxes with some x++ coding when you change the value?

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
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 429 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans