Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

How to update the primary key cross company?

(0) ShareShare
ReportReport
Posted on by 162

I have a data discrepancy, where I need to rename the vendor ids having same party number across all the legal entities to specific number. Anyway to achieve it? Q

  • Harshal Jain Profile Picture
    Harshal Jain 162 on at
    RE: How to update the primary key cross company?

    Hi ,

    I used this piece of code -

      while select  crosscompany : conCompanies
                * from vendTable
                 join PartyNumber from  partyTable order by PartyNumber
                      where   partyTable.RECID == vendTable.PARTY && (partyTable.PartyNumber == '000000126')
    
            {
    
    
    
                if(partyNum == '' || partyNum == partyTable.PartyNumber)
                {
                    vendTable.AccountNum = vendAccount;
                    vendTable.renamePrimaryKey();
                    partyNum = partyTable.PartyNumber;
    
                }
                }

  • Anton Venter Profile Picture
    Anton Venter 19,495 Super User 2025 Season 1 on at
    RE: How to update the primary key cross company?

    Good to hear it was solved. Could you verify the answer for future users? Thanks.

  • Harshal Jain Profile Picture
    Harshal Jain 162 on at
    RE: How to update the primary key cross company?

    Hi Mohit,

    Thanks for the reply. I was already using these things and was able to resolve my problem.

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: How to update the primary key cross company?

    Hi Harshal, You can use below sql script in SQL server to find how many records you need to change and based on number of records you can create the logic.

    select PARTY from VendTable
    join DIRPARTYTABLE
    on VENDTABLE.PARTY = DIRPARTYTABLE.RECID
    group by VendTable.PARTY
    Having count(VendTable.PARTY) > 1

    For x , you have to use crosscompany keyword to iterate all records, check these articles

    http://allaboutax.blogspot.com/2019/05/duplicate-records-in-dynamics-365.html

    https://www.d365stuff.co/update_recordset-but-cross-company/ (won't recommend to skip standard validations)

    As discussed, primary key can be updated using below article

    subscription.packtpub.com/.../renaming-the-primary-key

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 Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,160 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,962 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans