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

Notifications

Announcements

No record found.

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
    301,170 Super User 2025 Season 2 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
    301,170 Super User 2025 Season 2 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans