Inserting one record in multiple company

ebrahmaebrahma Member Posts: 36
edited 2004-06-16 in Navision Attain
I want to insert one record in to mulitple companies when inserted in any company.Any body knows the script lines ..pls tell..

Comments

  • RobertMoRobertMo Member Posts: 484
    can you use DataPerCompany=No property ?
               ®obi           
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  • kvbkvb Member Posts: 107
    try CHANGECOMPANY
  • RobertMoRobertMo Member Posts: 484
    what i mean: if you want the records to be allways the same for all companies you can use DataPerCompany=no.

    otherwise you shouldcreate some code using CHANGECOMPANY function...
               ®obi           
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  • afarrafarr Member Posts: 287
    But see http://www.navision.net/forum/topic.asp?TOPIC_ID=9491 which advises against setting DataPerCompany = NO. In particular these two posts that I'm taking the liberty to quote here:


    David Singleton:
    Firstly, whilst it seems simple, it is not a good idea to make the master records (Cust, item etc) as common to all companies, it just causes too many problems. Better is to write code that syncs them between all the companies, which is a really simple bit of code.


    Beaver:
    I must agree to David: Setting Customer to DataPerCompany=No seems to be simple, but it surely is not.
    In order to have consistent data, you must also set all the tables to DataPerCompany=No, to which fields in the customer table refer to. An example would be the Gen. Bus. Posting Group table.
    If you do not do that and you set up different Posting Groups in the companies, the validation of that field in table customer will fail.
    That need to make many more tables valid for all companies can lead to serious problems. Take the Payment Terms table. This is valid for customers AND vendors. If you make customers DataPerCompany=No than the Payment Terms table will have to be DataPerCompany=No as well. Then you cannot set up different payment terms for your vendors per company which you still might want to.
    Synchronizing is generally the better way to do it.
    Alastair Farrugia
  • RobertMoRobertMo Member Posts: 484
    I didn't say it is easy and without any concerns.
    Here's also a post, where I described a bit more about DataPerCompany and what you should be aware of:
    http://www.mibuso.com/forum/viewtopic.php?t=2524
               ®obi           
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  • ebrahmaebrahma Member Posts: 36
    I tried using CHANGECOMPANY function ,,I am not able to get the solution rather i am not approaching the solution correctly.Can any one please give me some sample code regarding CHANGECOPANY for inserting one record from one company to all the companies in the database.

    Thanks
    e-Brahma
  • FPulsfortFPulsfort Member Posts: 43
    create a global variable, e.g. Comp, from type record and Subtype 2000000006 "Company". In this table are all Compynies of your Database. The following example shows how one Item is inserted in all Companies.
    Create a funcion with Parameter Item of Type Record an Subtype 27 Item. This Record will be inserted in all other Comanies.
    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;
    

    Attention: This Routine does NOT validate any field in the other Companies!!! If you want to do this you have to assign every single value from teim to item2 and validate the fields. But remember: The tables (global and local records) which were refered to in the Validate-triggers belong to the active company!!! You have to use CHANGECOMPANY for this tables, too!!! To find all neccessary tables is a hard work. But this is your only way to use this function!

    Hope this helps.

    Regards,
    Frank
    
                            
  • ebrahmaebrahma Member Posts: 36
    your code is working great!
    Thanxs
Sign In or Register to comment.