D365 Finance & Operations and Dynamics AX Forum

Expand all | Collapse all

Validating new sales order information in AX 2012 R3

  • 1.  Validating new sales order information in AX 2012 R3

    Posted Jan 17, 2020 08:01 AM
    I have a need to validate the customer reference value when creating a new sales order to ensure that it has not been entered previously for the same customer. I have added the following X++ code into the canClose() method in the SalesCreateOrder form;
                customerReference = SalesTable.CustomerRef;
                if (CustomerReference != "")
                {
                    select localSalesTable
                        where localSalesTable.CustAccount == salesTable.CustAccount
                            && localSalesTable.CustomerRef == salesTable.CustomerRef
                            && localSalesTable.SalesType == SalesType::Sales;
                    if (localSalesTable)
                    {
                        warning(strFmt("Sales order '%1' already exists with customer reference '%2'. " +
                                       "Please review before continuing", localSalesTable.SalesId, customerReference));
                        ret = false;
                    }
                }


    When the code executes and a duplicated reference is entered by the user, the InfoLog message appears, but then the other entered information is lost and mandatory fields become underlined. Am I validating the information in the correct method? if so, what am I doing wrong?

    Thanks in advance



    ------------------------------
    Paul Fildes
    Steelite International Ltd
    Stoke-On-Trent
    ------------------------------
    Conference-AXUG_200x200


  • 2.  RE: Validating new sales order information in AX 2012 R3

    Posted Jan 20, 2020 01:26 AM
    Hi Paul,
    there are a couple of places where it would be better to place the code.
    You can place it in the validateField method, where you're validating different fields and action them accordingly.
    Or you can place it in the insert method, so when it's written to the DB it will check for duplicate orders.
    I would probably place it in the SalesTableType_Sales class.
    Hope this helps.

    ------------------------------
    Soren Normann Rasmussen
    SSS Australia
    Murarrie
    ------------------------------

    Conference-AXUG_200x200


  • 3.  RE: Validating new sales order information in AX 2012 R3

    Posted Jan 20, 2020 07:00 AM
    Hi Soren,
    Many thanks for your suggestion. I have taken your advice and added a ValidateField method in the SalesTableType_Sales class. It seems to work perfectly.

    Paul

    ------------------------------
    Paul Fildes
    Steelite International Ltd
    Stoke-On-Trent
    ------------------------------

    Conference-AXUG_200x200


If you've found this thread useful, dive deeper into User Group community content by role