Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)
Answered

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

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: ValidateWrite() is called when I click "New" (CommandButton)

    Forget everything. I got it.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: ValidateWrite() is called when I click "New" (CommandButton)

    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

  • Martin Dráb Profile Picture
    Martin Dráb 230,514 Most Valuable Professional on at
    RE: ValidateWrite() is called when I click "New" (CommandButton)

    What do you mean?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: ValidateWrite() is called when I click "New" (CommandButton)

    What about the leave or leaveRecord methods in this case ?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: ValidateWrite() is called when I click "New" (CommandButton)

    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
    Community Member Microsoft Employee on at
    RE: ValidateWrite() is called when I click "New" (CommandButton)

    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().

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,514 Most Valuable Professional on at
    RE: ValidateWrite() is called when I click "New" (CommandButton)

    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
    Community Member Microsoft Employee on at
    RE: ValidateWrite() is called when I click "New" (CommandButton)
        int ret;
        #Task
        ;
    
        if (_taskId == #taskNew)
        {
            if (SYCFMRentalTable.RentalID)
            {
                SYCFMRentalTable_ds.write();
            }
        }
    
        ret = super(_taskId);
    
        return ret;
  • Martin Dráb Profile Picture
    Martin Dráb 230,514 Most Valuable Professional on at
    RE: ValidateWrite() is called when I click "New" (CommandButton)

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: ValidateWrite() is called when I click "New" (CommandButton)

    (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

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey Pt 2

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,820 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,514 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans