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)

Validating input value of form

(0) ShareShare
ReportReport
Posted on by 495

Senores, I need some help in validating a field in AX 2012 R2...

Here is what i have:

I override the method on the DS field control

public boolean validate()

{

   AgreementLineQuantityCommitment   agreementLineQuantityCommitment;

  boolean ret;

   ret = super();

   if(agreementLineQuantityCommitment.PricePerUnit<100)

       ret= checkFailed('Any message that you may want to display.');

   return ret;

}

I want to make sure the field value is greater than the calculated/recommended cost of an item.

Please any help suggestions would be greatly appreciated.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    udaY-ch Profile Picture
    5,133 on at

    Hi,

    You haven't got the actual buffer on the variable agreementLineQuantityCommitment.

    For instance,

    Select agreementLineQuantityCommitment where agreementLineQuantityCommitment.Agreement = AgreementRecId;

    Hoping you will be able to get the agreement RecId in the form.

    /Uday.

  • Suggested answer
    Rustem Galiamov Profile Picture
    8,072 on at

    Hi Lionel07!

    If AgreementLineQuantityCommitment is the data source of the form and your method is the method in the field from this DS then you don't need to declare a new variable agreementLineQuantityCommitment because you already has it.

    Try to put breakpoint into this method and check it.

  • Suggested answer
    startax Profile Picture
    1,845 on at

    Hi,

    You can find details of how to erite code in validate field() in table

    https://jkmsdax2012.wordpress.com/tag/validate-field-method/

  • Lionel07 Profile Picture
    495 on at

    8640.image.PNGThanks for this, I did saw this during my research but where do i put this code? should it be here? see image

    Please advise.

  • Suggested answer
    Rustem Galiamov Profile Picture
    8,072 on at

    The validateField() method can be overridden on the table, not on DS table on the form or on the field of DS table. In the methods node of the field on DS you can override validate() method. In your case try to check AgreementLineQuantityCommitment (Aline) table:

    Screenshot-2018_2D00_11_2D00_20-at-22.44.15.png

  • Lionel07 Profile Picture
    495 on at

    Thanks for this Rustem,

    I am currently using the method on the table.....in my method I need to get the value of a return method (InventTable.costPrice()) based on the item that the user enter on the sales agreement line, the input value for PricePerUnit must be greater than or iqual to  the value from InventTable.costPrice(). How do I make that comparison?

    Here is what I have so far:

    public boolean validateField(fieldId _fieldIdToCheck)

    {

       boolean ret;

       AgreementLineQuantityCommitment lineOrig;

       InventTrans inventTrans;    

       int cv = inventTrans.costValue();  // Can i do this?

       ret = super(_fieldIdToCheck);

       if (ret)

       {

           switch (_fieldIdToCheck)

           {

               case fieldNum(AgreementLineQuantityCommitment, ProductUnitOfMeasure):

                   if (this.isReleased())

                   {

                       ret = checkFailed("@SYS137220");

                   }

                   break;

               case fieldNum(AgreementLineQuantityCommitment, PricePerUnit):

                   if (this.PricePerUnit =< cv)

                   {

                       //ret = inventTrans.costValue();

                       ret = checkFailed('This must be more than cost price');

                   }

                   break;

           }

           if (!ret)

           {

               lineOrig = this.orig();

               this.(_fieldIdToCheck) = lineOrig.(_fieldIdToCheck);

           }

       }

       return ret;

    }

    My question really is if how do I get the the value from   inventTrans.costValue();  so i can use it to do the comparison?

  • Suggested answer
    Rustem Galiamov Profile Picture
    8,072 on at

    InventTrans has many records per item. How you want to relate AgreementLineQuantityCommitment records with InventTrans record? InventTrans.costValue() it's a cost value of particular transaction not of Item.

    Maybe if you provide your business requirements we can suggest better solution.

  • Lionel07 Profile Picture
    495 on at

    Thanks again Rustem, So in my environment because users enter the unit price when creating sales agreement, I want to ensure that a price which is less than the cost price of an item is not entered.

    So on the sales agreement line when i enter the price for am item, that price must not be less than the cost price of the item. If if is then i error message should pop up and  does  not allow the user to continue until the value enter has changed.

    This is the reason I was thinking to get the cost price of the items using InventTrans.costValue() and compare it with the value the user would enter on the control agreementLineQuantityCommitment.PricePerUnit

    Thanks for helping

  • Rustem Galiamov Profile Picture
    8,072 on at

    I have one more question. When you create agreement line, do you fill an inventory dimension?

  • Lionel07 Profile Picture
    495 on at

    Yes, we would enter the quantity, site warehouse, unit price.. As you can see in the image attached.

    1588.image1.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

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