web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)
Answered

ValidateWrite() is called when I click "New" (CommandButton)

(0) ShareShare
ReportReport
Posted on by

Hi Community,

I found out that my validateWrite() is called, when I click on "New" (CommandButton) in my Form.

I wrote a method which shall check if a vehicle is available in a time period.

I called the method in my validateWrite() of the table. I ask myself how can I avoid that the validateWrite() is called, when I click "New" CommandButton.
It doesn't actually make any sense to me...

But there are either one Option, that when you click "New" the validateWrite() is called automatically!

Or that a record before wasn't really saved, but is still in the table, even though I didn't save it correctly but closed the form!

I listed You the methods.

public boolean validateWrite()
{
    boolean available;
    boolean ret;
    ;

    available = this.checkVehicleAvailability();

    if (available == true)
    {
        ret = super();
    }
    else
    {
        ret = false;
    }

    return ret;
}


checkVehicleAvailability()

public boolean checkVehicleAvailability()
{
    SYCFMRentalTable    rentTable;
    boolean             available;
    ;

    while select VehicleId, StartDate, EndDate
        from rentTable
            where rentTable.VehicleID == this.VehicleID
            {
                if (this.StartDate >= rentTable.StartDate && this.StartDate <= rentTable.EndDate)
                {
                    available = checkFailed("Vehicle already reserved"); //Labels
                }
                else if (this.EndDate >= rentTable.StartDate && this.EndDate <= rentTable.EndDate)
                {
                    available = checkFailed("Vehicle already reserved"); //Labels
                }
                else if (rentTable.StartDate >= this.StartDate && rentTable.StartDate <= this.EndDate)
                {
                    available = checkFailed("Vehicle already reserved"); //Labels
                }
                else
                {
                    available = true;
                }
            }

    return available;
}


*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    238,745 Most Valuable Professional on at

    Can you please show us the call stack leading to validateWrite()?

  • Community Member Profile Picture
    on at

    (C)\Data Dictionary\Tables\SYCFMRentalTable\Methods\validateWrite22(C)\Classes\FormDataSource\validateWrite0(C)\Forms\SYCFMRentals\Data Sources\SYCFMRentalTable\Methods\validateWrite6(C)\Classes\FormDataSource\write0(C)\Forms\SYCFMRentals\Data Sources\SYCFMRentalTable\Methods\write5(C)\Forms\SYCFMRentals\Methods\task17(C)\Classes\SysSetupFormRun\task27

    ValidateWriteProblemCallStack.PNG

  • Martin Dráb Profile Picture
    238,745 Most Valuable Professional on at

    What code do you have in SYCFMRentals.task()?

  • Community Member Profile Picture
    on at
        int ret;
        #Task
        ;
    
        if (_taskId == #taskNew)
        {
            if (SYCFMRentalTable.RentalID)
            {
                SYCFMRentalTable_ds.write();
            }
        }
    
        ret = super(_taskId);
    
        return ret;
  • Verified answer
    Martin Dráb Profile Picture
    238,745 Most Valuable Professional on at

    That's seems to be the answer.

    write() (and validateWrite()) is called when you create a new record because you have code doing it in task().

  • Community Member Profile Picture
    on at

    Yes, and now when I am commenting out SYCFMRentalTable_ds.write(), I face the Problem that after I insert the record, I can't get away from it, it always then after saving or clicking away calls validateWrite().

  • Community Member Profile Picture
    on at

    I have commented out my validateWrite() in the Table.

    And now, in my Form when I click new, a new Record won't be made only the info will come up.

    When uncomment everything, then I can make a record entry, but with the same Problems as before, since I had uncommented

    SYCFMRentalTable_ds.write(); in the Task Method just for the try.

    public boolean validateWrite()
    {
        boolean available;
        boolean ret;
    
        container myCallStack;
        int i;
        str whatToWrite;
        ;
    
        info("Hi Caro");
    
        //available = this.checkVehicleAvailability();
    //
        //if (available == true)
        //{
            //ret = super();
        //}
        //else
        //{
            //ret = false;
        //}
    
        //myCallStack = xSession::xppCallStack();
        //for(i=1; i<=conlen(myCallStack); i++)
        //{
            //whatToWrite += conpeek(myCallStack, i);
        //}
    //
        //info(whatToWrite);
    
        return ret;
    }


  • Community Member Profile Picture
    on at

    What about the leave or leaveRecord methods in this case ?

  • Martin Dráb Profile Picture
    238,745 Most Valuable Professional on at

    What do you mean?

  • Community Member Profile Picture
    on at

    I clicked on "New" Button. The ValidateWrite() was of Course not called.

    Entered the Data.

    Saved the record. Infolog showed up "Hi Caro".

    I closed the Infolog.

    Clicked on "New" Button, and then the error "A new number cannot be assigned because Rent_000046 has not been saved or deleted." came up.
    I guess it is because I have uncommented the SYCFMRentalTable_ds.write();

    I guess I am depending on this line of Code (So I have to uncomment it) , but I still have to somehow then elude the write(), when I want my validateWrite() not to be called when I click on "New".

    ValidateWriteProblemCallStack1.PNG

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Sagar Suman Profile Picture

Sagar Suman 2 Super User 2026 Season 1

#1
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#1
Pratik Bhosle Profile Picture

Pratik Bhosle 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans