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

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Validation on the fields

(0) ShareShare
ReportReport
Posted on by 618

Hi Guys,

I have a form & table called CommissionTrans  where I have the dropdown field  settlementId. I need to select the SettlementId for each transactions manually on this form . I have to add a validation that I should be able to select one settlementId for one transaction only. If I select the same ID for next transaction it should show an error that its already used for another transaction. how can I do it ? which validation method to be added and how the code should be. 

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    235,804 Most Valuable Professional on at
    RE: Validation on the fields

    Don't use a regular button with clicked(). Use a command button with Command = OK and override closeOk(). The validation can be done in canClose(). Nevertheless removing all the code and using a lookup form would likely be a better approach. Then you would use validateWrite() and or validateField() as discussed before.

    I don't know what's the purpose the while select + delete; it looks suspicious. And the fact there is no condition must be a bug.

    If you really need some deletion, remember never put any code like this on client. It meaninglessly fetches all CommissionTransSettlement records from database to client just to send delete commands (one by one) back to database. It's a performance killer. It's made even worse by the long-living transaction created on client. *If* you need this logic, put it in a server-side method and replace the while select with delete_from.

  • D365  beginner Profile Picture
    618 on at
    RE: Validation on the fields

    Hi Martin,

    Thanks for the reply.

    I Just made some changes in the requirement as I created a new child form (CommissionTransSettlement) and I would like to select the settlement Id from the child form. In this case I am trying to modify the clicked method already there on the button from where I can select the SettlementId.  how can I call the function validatefield() created on the table commissiontrans on this form.

    void clicked()

    {

     commissionTrans CommissionTrans;

      super();

     ttsbegin;

     while select forUpdate CommissionTransSettlement

     {

     CommissionTransSettlement.Delete();

     }

     ttscommit;

     ttsbegin;

     select forUpdate CommissionTrans

                   where CommissionTrans.InvoiceId == CommissionTransSettlement.InvoiceId

                      &&  CommissionTrans.EmplId == CommissionTransSettlement.EmplId  ;

     CommissionTrans.SettlementId = CommissionTransSettlement.SettlementId;

     CommissionTrans.update();

      ttscommit;

     element.close();

    }

  • Suggested answer
    Martin Dráb Profile Picture
    235,804 Most Valuable Professional on at
    RE: Validation on the fields

    Which method you should use depends on when you want to run the validation. For example, if you want to do it on save, override validateWrite() method on the table.

    Simply a run a query to check whether there already is another transaction with the same settlement ID and return false if it is. You'll likely want to create an index on SettlementId, to make this query efficient.

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…

Mansi Soni – Community Spotlight

We are honored to recognize Mansi Soni as our August 2025 Community…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Syed Haris Shah Profile Picture

Syed Haris Shah 9

#2
Mea_ Profile Picture

Mea_ 4

#3
KP-31070522-0 Profile Picture

KP-31070522-0 3

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans