Virtual Companies

are used to share data between companies.

If you set the SaveDataPerCompany table flag to false, contained data is the same for every company.

Data within virtual companies is shared between the companies contained within the virtual company, many virtual companies may be defined within a database, and there may also be companies not contained within virtual companies.

AOT/Data Dictionary/Table collections: here you can define the list of shared tables between the companies and attach it to the virtual company with Administration/Setup/Virtual company accounts

But let's say you want to share the item table (InventTable) within the virtual company VVV containing companies AAA and BBB. If you create a new item record, Dynamics Ax creates automatically three InventTableModule records within the current company AAA. If the InventTableModule is not shared, in company BBB the InventTableModule records are not created, and you cannot see the new Item in the Item Master. So you need to create the records manually.

You have to modify the InventTableModule.insert method: void insert {   // HARPA, 11.04.2006 --> VirtualDataAreaList    virtualDataAreaList, virtualDataAreaFind; InventTableModule      otherInventTableModule; ;   // HARPA, <--

if (this.price   || this.markup) this.priceDate= systemdateGet;

super;

// HARPA, --> //check if company is part of a virtual company if (!xDataArea::find(this.dataAreaId).isVirtual) {       select firstOnly virtualDataAreaFind where virtualDataAreaFind.Id == this.dataAreaId; if (virtualDataAreaFind) {           while select virtualDataAreaList where virtualDataAreaList.virtualDataArea   == virtualDataAreaFind.virtualDataArea && virtualDataAreaList.Id                != this.dataAreaId {               changeCompany(virtualDataAreaList.Id) {                   otherInventTableModule = NULL; buf2buf(this, otherInventTableModule); if (otherInventTableModule.dataAreaId == virtualDataAreaList.Id) otherInventTableModule.doInsert; }           }        }    }    // <-- }

It would also be a good idea to delete the records if the item is deleted. InventTable.delete: public void delete {   ...

// HARPA, 11.04.2006 --> VirtualDataAreaList    virtualDataAreaList, virtualDataAreaFind; InventTableModule      findInventTableModule; InventItemLocation     findInventItemLocation; // HARPA, <-- ;

ttsbegin;

...

// HARPA, 11.04.2006 --> //check if company is part of a virtual company if (!xDataArea::find(this.dataAreaId).isVirtual) {       select firstOnly virtualDataAreaFind where virtualDataAreaFind.Id == this.dataAreaId; if (virtualDataAreaFind) {           while select virtualDataAreaList where virtualDataAreaList.virtualDataArea   == virtualDataAreaFind.virtualDataArea && virtualDataAreaList.Id                != this.dataAreaId {               changeCompany(virtualDataAreaList.Id) {                   delete_from findInventTableModule where findInventTableModule.ItemId       == this.ItemId && findInventTableModule.dataAreaId   == virtualDataAreaList.Id; delete_from findInventItemLocation where findInventItemLocation.ItemId      == this.ItemId && findInventItemLocation.dataAreaId  == virtualDataAreaList.Id; }           }        }    }    // HARPA, <--

super;

ttscommit; }

Sometimes it is necessary to update fields in all companies like this new method in InventTableModule: void SF_updateFieldInAllCompanies(FieldId _fieldId) // HARPA, 04.07.2006 --> {   VirtualDataAreaList     virtualDataAreaList, virtualDataAreaFind; InventTableModule      otherInventTableModule; ;   ttsbegin; //check if company is part of a virtual company if (!xDataArea::find(this.dataAreaId).isVirtual) {       select firstOnly virtualDataAreaFind where virtualDataAreaFind.Id == this.dataAreaId; if (virtualDataAreaFind) {           while select virtualDataAreaList where virtualDataAreaList.virtualDataArea   == virtualDataAreaFind.virtualDataArea && virtualDataAreaList.Id                != this.dataAreaId {               otherInventTableModule.company(virtualDataAreaList.Id); changeCompany(virtualDataAreaList.Id) {                   otherInventTableModule = InventTableModule::find(this.ItemId, this.ModuleType, true); otherInventTableModule.(_fieldId) = this.(_fieldId); otherInventTableModule.update; }           }        }    }    ttscommit; }

There is a problem with the method SmmDocuments.getDataAreaId - you have to add every table in the table collection that uses documents: // HARPA, 13.06.2006 --> case tableName2Id(tableStr(InventTable))   : common = InventTable::findRecId(_refRecId); break; // HARPA, 13.06.2006 <--

And if you need to sum the invoices of all companies within the virtual company: if (!xDataArea::find(curExt).isVirtual) {   select firstOnly virtualDataAreaFind where virtualDataAreaFind.Id == curExt; if (virtualDataAreaFind) {       while select virtualDataAreaList where virtualDataAreaList.virtualDataArea   == virtualDataAreaFind.virtualDataArea {           custInvoiceTrans.company(virtualDataAreaList.Id); while select custInvoiceTrans where (...) {               do something with custInvoiceTrans ... }       }    } }

Hope this helps a little if you struggle with virtual companies.

harald --80.81.131.3 05:02, 4 July 2006 (EST)