web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Updating CountryRegionId in TaxVatNumTable

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    306,446 Super User 2026 Season 1 on at

    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.

  • Community Member Profile Picture
    on at

    Hi André

    I have correct it, butI get the same error on the same customer.

  • André Arnaud de Calavon Profile Picture
    306,446 Super User 2026 Season 1 on at

    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.

  • Syed Tahseen Hussain Profile Picture
    30 on at

    May i know which form in ax 2012 i can add value to this table. ?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans