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 —————————— ——————————————-
Please note:
This action will also remove this member from your connections and send a report to the site admin.
Please allow a few minutes for this process to complete.
Report
You have already reported this .
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!