Search code examples
axaptadynamics-ax-2012x++

Insert into table when record does not exist


When inserting a VAT number for a customer, it checks if the value I enter exists in the TaxVATNumTable.

This check is active in the method: checkVATNum in the table TaxVATNumTable:

if (!TaxVATNumTable::existOptionalCountryRegion(vatNum))
ret = checkFailed(strFmt("@SYS83770", vatNum, fieldId2pname(common.TableId, fieldId), countryRegion, tableId2pname(tableNum(TaxVATNumTable))));

I want to comment out the: ret = ... line and build in a code that the VAT number I enter at the customer is being inserted in the TaxVATNumTable.

This table does not have an insert method, what is the best way to approach this situation? Create an insert method for this?


Solution

  • The checkVATNum() method should not be modified as you always want to confirm that value exists.

    What you should do is identify where the inserting action is happening, and perform a check and insert before the checkVATNum() logic.

    If a table doesn't have an insert() method, you just right click on the table methods and click Override Method > Insert. If you do this though, insert_recordset operations will not be efficient against the specific table as the insert() logic will need to be called, and it will break down to a regular style operation.