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)

Prevent closing a form

(0) ShareShare
ReportReport
Posted on by

A new  two customized fields are added to HCMEmployment table, in HCMWorker form I need to perform the following:

-If the value of the first customized field is not zero and the value of the second customized field is still zero , the form should not be closed anda waring  message should be displayed for the user saying that this field should be filled.

The required checking and message code is added to ValidateWrite method on HcmEmployment datasourse on the Hcmworker form, the question is how can I prevent closing the HCMWorker form ?????

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Denis Macchinetti Profile Picture
    16,444 on at

    Hi Maram

    You have set the Ret variable to False ? E.g.

    public boolean validateWrite()

    {

       boolean ret;

       ret = super();

       if ( .... )

           ret = checkFailed("Error");

       return ret;

    }

    If Ret is set to False, you prevent the form closing.

    Regards

  • Suggested answer
    Martin Dráb Profile Picture
    237,959 Most Valuable Professional on at

    If you add a validation to validateWrite(), it's executed automatically when a record is being saved. Normal closing a form tries to save modified records automatically and it executes validateWrite(). If it fails (the method returns false), the form is not closed.

    If the form is left without saving or there're no modified data, validateWrite() is not called, of course.

    If you want a validation when closing a form regardless whether a record is being saved, validateWrite() is not a good choice. Use canClose() on the form instead.

  • maram fraij Profile Picture
    on at

    I try to use can close () method, but the problem I face is that when from is not closed because of incorrect value for second customized field as required, and the user modifies the value of the that field  and the form is closed successfully, the  modified value is not saved  what should I do ?

  • Martin Dráb Profile Picture
    237,959 Most Valuable Professional on at

    How are you (not) saving the record?

  • maram fraij Profile Picture
    on at

    Sorry I do not understand, would you please explain more ?

  • Martin Dráb Profile Picture
    237,959 Most Valuable Professional on at

    You said that "the modified value is not saved", so my question is how you're saving it. Can you show us your implementation and describe the observed behavior?

  • maram fraij Profile Picture
    on at

    Nothing is added to  prevent saving the modified data. I noticed this behavior I assume that after modifying  the value and the worker form is closed successfully the new value should be saved but I find the original  incorrect value which prevents closing the form,  that means saving   for the modified value is not performed.

  • Suggested answer
    Dick Wenning Profile Picture
    8,705 Moderator on at

    overwrite canClose in the form

    look in the AOT , there is a lot of examples

    public boolean canClose()

    {

       boolean ret = true;

       if (this.closedOk())

       {

           if (agreementLineRecId != aLine.RecId) //only check if another agreement line is selected.

           {

               ret = aLine.canLinkTo(salesPurchLine);

           }

       }

       if (ret)

       {

           ret = super();

       }

       return ret;

    }

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
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans