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)

Validation on the fields

(0) ShareShare
ReportReport
Posted on by 634

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)
  • Suggested answer
    Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    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.

  • D365  beginner Profile Picture
    634 on at

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

    }

  • Verified answer
    Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    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.

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