Multicompany updates with many tables

thomdossthomdoss Member Posts: 3
Hello,

I have read myriad posts on changecompany, business logic, etc. and while I agree that it is a bad practice to push data from a central company to other companies, I have inhertied a design that tells the client that is what we will do. At least the desire to replicate is only for master records. The only way I see to safely replicate a row between companies is to pass not just the affected row, but also pass each row in each related table that is referrenced by the replicated row. Since even a casual inspection of relations will show that the customer table has 28 columns that are foreign keys, writing table specific code to capture the rows would not only be tedious, it would only be valid until someone creates a new related column that my code does not know about.

So I wrote a routine using recordref, fieldref and the field table that would find all of the related tables to any table, and persist the information into an 'intercompany replication queue'. Then I could just run the code in the destination companies and 'pull' the requisite data. Then I noticed some scary postings about recref and changecompany in the RCT. Not knowing if those were still an issue, and being on a tight deadline, I decided that the answer was to just extend my 'drill down' routine to drill in to the fields for each table as well and store them. That made the code a little more complex, but at least I had a sustainable, adaptable answer that would survive any issues I could foresee.

All was good until I realized that I can't seem to find a way to persist a fieldref in a table. I was hoping I could stream it to a blob, but I couldn't figure out how. Now the code becomes less elegant because I need to extract the value, and deal with complex types. I imagine I can solve it if I continue down this path, but it leads me to wonder if I shouldn't confirm if there are any changecompany issues related to recordref. If not, I don't need to deal with the data at the field level.

With that background, if I have a list of tables and key values in a table, would code that processes those using recref work under the RTC? In a nutshell, here is the code I am concerned about:

Running in destination company.

recref.open(18,false,Master Company');
.. Set fldref for recref primary key from queue table)
recref.find('=);
recref2.open(18,false); (destination company)
.. Set fldref for recref2 primary key from queue table)
if recref2.find('-) then
update fields from recref
recref2.modify
else
update fields from recref
recref2.insert

And yes, I know how bad the assumptions are in this design, but it is what the client wants. What I need to confirm is:

1) Are there any known issues with the RTC using abstract functions in this manner?
2) Since there does not appear to be a recref.transferfields, is there another a way to 'bulk copy' fields from the recref without needing to update each field individually?
3) Will this work for blobs? I have seen postings indicating that copying blob fields from recordref variables is problematic, even though calcfield is used. I can deal with that if it is the only issue.

I know there is a lot of code missing, but I am trying to keep the sample simple. Some of the posts I read seemed to indicate that this code under the RTC would result in recref and recref2 pointing at the same record. (The customer in the current company)

Thanks in advance for any help,

Thom Doss

Comments

  • kinekine Member Posts: 12,562
    Do not forget that some foreign key fields are with multiple relations (conditioned by another field) and these you will not see in the table relations!
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.