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 :
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
    237,744 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
    237,744 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
    237,744 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
    237,744 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

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#2
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

#2
Rahul.p Profile Picture

Rahul.p 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans