Synchronizing contacts between companies

grefugrefu Member Posts: 3
Hi.
I'm working in a company which has 7 companies inside Dynamics NAV. Most of them are only using accounting module. They've just created a new company which it's going to work with a own module based on contacts module. As they need to work with contacts already created in the "master" company, I need to share them between companies.
I thought about using "DataPerCompany" property but I read about many problems that might occur. Then I look into about how to synchronize companies and I found the code below:
Comp.FIND('-');
REPEAT
  IF Comp.Name <> COMPANYNAME THEN BEGIN
    Item2.CHANGECOMPANY(Comp.Name);
    Item2.COPY(Item);
    If not Item2.insert THEN
      Item2.MODIFY;
  END;
UNTIL Comp.NEXT = 0;
where "comp" is a record from 2000000006 table "Company"

I'm not pretty sure that how to use this because contacts can be created by standard Contacts Form or with a Form from that own development, which uses .INSERT and .VALIDATE methods. Then, must I use this code in OnInsert trigger? in OnValidate trigger? In both?
Regards.

Comments

  • Borrachon2013Borrachon2013 Member Posts: 5
    Hi,

    Everybody seems to be afraid of 'shared tables' .... I use it a lot and I would recommend it in this case too.
    I use very often within 1 database with plural companies the tables Vendor, Customer, Item as 'Shared tables'. All ledger entry tables should NOT be shared. It works....
    I would do this with "contact' too.... I do not see any major problem.

    Saluti Raymond
    Simple is simply the best
  • grefugrefu Member Posts: 3
    Thank you. But how many tables are affected by this change? I mean, that If I change "DataPerCompany" in Contact table, I'll have to change Vendor, Client, etc.. too, haven't I?
  • rocatisrocatis Member Posts: 163
    The reason many people dislike using the DataPerCompany for existing tables is quite simple:

    Unless you include all related tables you're gonna end up with problems sooner or later.

    Also, consider the situation where you've set DataPerCompany=No for the Customer table (or another table with related ledger entries). If you delete the Customer in one of your companies, you could be left with orphaned ledger entries in another -> one hell of a mess.
    Brian Rocatis
    Senior NAV Developer
    Elbek & Vejrup
  • rocatisrocatis Member Posts: 163
    The reason many people dislike using the DataPerCompany for existing tables is quite simple:

    Unless you include all related tables you're gonna end up with problems sooner or later.

    Also, consider the situation where you've set DataPerCompany=No for the Customer table (or another table with related ledger entries). If you delete the Customer in one of your companies, you could be left with orphaned ledger entries in another -> one hell of a mess.
    Brian Rocatis
    Senior NAV Developer
    Elbek & Vejrup
Sign In or Register to comment.