[Tip] Find duplicate entries
This tip is all about the way you can check if a Serial number, social security, VAT number or any other unique code is already used somewere in your table?
You can just use an SQL query and check the number of found records. If any.... your unique code has already been used!!!
var query = 'select companiesid, vat_code, companyname from companies where vat_code = ' + globals.newVatCode;
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(), query, null, 1);
if (dataset.getMaxRowIndex() > 0) //Found at least one record
{
dataset.rowIndex = 1; // put "focus" on first dataset record
application.beep(); // warning acoustic sound
plugins.dialogs.showWarningDialog( "Warning", "VAT number: " + globals.newVatCode + " already in use\nMoving to company: " + dataset[3] ,"Ok"); // Show warning (two line message)
foundset.selectRecord(dataset[1]); // jumps using primary key value
}
As usual, I hope you will like it,
bye
Enrico
Comments (3)