Hi
I want to update country region Id's in TaxVatNumTable.
If the record doesnt already exists, it must be insterted.
I import the new values from a .csv file.
Here is my code. When I run the code, I get an error, that "The record already exists". But its just the VatNum that exists in the table is for another company.
ttsBegin; while (file.status() == IO_Status::Ok && conLen(conRecord) > 0) { contactView.clear(); counter++; Progress.incCount() ; nowHandling++; accountNum = strLwr(conPeek(conRecord, 2)); select forUpdate firstOnly RecId from tmpcustTable where tmpcustTable.AccountNum == accountNum; name = conPeek(conRecord, 1); // Navn name = strLRTrim(name); land = conPeek(conRecord, 7); // Land tmpcustTable.VATNum = conPeek(conRecord, 6); if (!land) { // Skal sættes (CountryRegionId) ellers fejl ved insert af adresser land = 'DNK'; } else { logisticsAddressCountryRegion = LogisticsAddressCountryRegion::findByISOCode(land); land = logisticsAddressCountryRegion.CountryRegionId; } if(tmpcustTable && tmpcustTable.VATNum != '') { select forUpdate taxVATNumTable where taxVATNumTable.VATNum == tmpcustTable.VATNum && taxVATNumTable.Name == name; if(taxVATNumTable) { taxVATNumTable.CountryRegionId = land; taxVATNumTable.doupdate(); tmpcustTable.update(); } else { taxVATNumTable.CountryRegionId = land; taxVATNumTable.doInsert(); } } conRecord = file.read(); } } ttsCommit;
*This post is locked for comments
May i know which form in ax 2012 i can add value to this table. ?
Check the indexes on the TaxVatNumTable which are set to unique. Then also use the debugger to find out if the error is caused on updates or inserts. Then you might find your cause.
Hi André
I have correct it, butI get the same error on the same customer.
Hi Mahyar,
In the coding where you insert a new record you only fill the country/region field. You should also populate the VATNum value.
Mohamed Amine Mahmoudi
100
Super User 2025 Season 1
Community Member
48
shanawaz davood basha
6