Skip to main content

Notifications

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

  • Syed Tahseen Hussain Profile Picture
    30 on at
    RE: Updating CountryRegionId in TaxVatNumTable

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

  • André Arnaud de Calavon Profile Picture
    294,851 Super User 2025 Season 1 on at
    RE: Updating CountryRegionId in TaxVatNumTable

    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.

  • Community Member Profile Picture
    on at
    RE: Updating CountryRegionId in TaxVatNumTable

    Hi André

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

  • Suggested answer
    André Arnaud de Calavon Profile Picture
    294,851 Super User 2025 Season 1 on at
    RE: Updating CountryRegionId in TaxVatNumTable

    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.

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Microsoft Dynamics AX (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 100 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 48

#3
shanawaz davood basha Profile Picture

shanawaz davood basha 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans