Validating new sales order information in AX 2012 R3

  • Validating new sales order information in AX 2012 R3

    Posted by DSC Communities on January 17, 2020 at 8:01 am
    • Paul Fildes

      Member

      January 17, 2020 at 8: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
      ——————————

    • Soren Normann Rasmussen

      Member

      January 20, 2020 at 1: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
      ——————————
      ——————————————-

    • Paul Fildes

      Member

      January 20, 2020 at 7: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
      ——————————
      ——————————————-

    DSC Communities replied 5 years, 7 months ago 1 Member · 0 Replies
  • 0 Replies

Sorry, there were no replies found.

The discussion ‘Validating new sales order information in AX 2012 R3’ is closed to new replies.

Start of Discussion
0 of 0 replies June 2018
Now

Welcome to our new site!

Here you will find a wealth of information created for peopleĀ  that are on a mission to redefine business models with cloud techinologies, AI, automation, low code / no code applications, data, security & more to compete in the Acceleration Economy!