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)

How to set mandatory field in form with conditions ?

(0) ShareShare
ReportReport
Posted on by 3,805

Hi all.. Please help me.

 

Inventory Management --> Journals --> Movement

i have two name in Journal Movement :

* MOV-out

* MOV-in

5545.1.jpg

And then klik Lines.

in Lines i want to set Mandatory for field Cost Price and Quantity with condition.

If Journal name MOV-in, then field Cost Price set mandatory.

But, if MOV-out then Quantity set mandatory, and Cost Price not mandatory.

0250.2.jpg

Please help me, where i put conditions and How?

Thanks all..

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Sohaib Cheema Profile Picture
    49,438 User Group Leader on at

    There can be many ways to address this issue. One suitable ways seems to write validation on VlaidateWrite() method of table with conditions such as with below pseduocode

    If(journalType == MoveIn obla blab bla)

    {

                    If(!this.coostPrice)//! Represents NOT

    {

                    Ret = checkfailed(‘throw error to user’);

    }

    }

     

    And so on.

    If you just want it to be on user interface level, you can write same on active() method of DataSource.

  • Verified answer
    Heinz Schweda Profile Picture
    1,367 on at

    You have to modify validateWrite() of table InventJournalTrans like Sohabib Seema supposed to.

    Additionally you can modify the interface, so that the formcontrols are marked as mandatory. You can do this by overwriting the active-method of the dataSource InventJournalTrans like this:

    public int active()

    {

       int ret = super();

       inventJournalTrans_ds.object(fieldNum(inventJournalTrans, Qty)).mandatory(inventJournalTrans.inventJournalTable().JournalNameId == 'Mov-Out');

       inventJournalTrans_ds.object(fieldNum(inventJournalTrans, CostPrice)).mandatory(inventJournalTrans.inventJournalTable().JournalNameId == 'Mov-In');

       return ret;

    }

    But note that this modification only creates the "red line" in the form control, you have to check the values in the validateWrite() of InventjournalTrans.

    public boolean validateWrite()

    {

       boolean isValid;

       ...existing code in this method

       if(this.inventJournalTable().journalNameId == 'Mov-Out' && !this.Qty)

       {

           isValid = checkfailed('Field Quantity missing');

       }

       if(this.inventJournalTable().journalNameId == 'Mov-In' && !this.CostPrice)

       {

           isValid = checkfailed('Field Cost price missing');

       }

       return isValid;

    }

  • fajar Profile Picture
    3,805 on at

    Thanks Heinz Schweda.

  • fajar Profile Picture
    3,805 on at

    Thanks Sohaib Cheema.

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