Now let's try to answer a practical question: how to use the XDTO mechanism to transfer data from one configuration to another, where the configurations are different.
It is important to understand that the schema "http://v8.1c.ru/8.1/data/enterprise/current-config" is suitable for data exchange between identical configurations and allows performing conversion between ObjectXDTO<->1C Object. You can use this!
Next, since we have different configurations, during the transfer we need to perform data transformation at some stage (export/import). This is usually done during the export stage - let's not deviate from tradition, moreover, this usually has several advantages.
1. To generate export data, we need the schema of the receiving configuration. Let's export it to a file: in the receiving configuration, right-click on the "XDTO Packages" node in the configuration tree / Export XML configuration data schema...
2. Let's start exporting. To generate export data, we create a factory based on the schema, specifying the path to the receiving configuration's schema file:
3. Let's create a TypeXDTO type to hold data from the source configuration:
Note that this TypeXDTO object maps the type of the receiving configuration, because our factory object instance works according to the schema loaded from the file, not according to the data of the current configuration.
4. Let's create an ObjectXDTO based on the type, and a 1C object from the source configuration:
5. Fill the ObjectXDTO by performing necessary data transformations
6. Write the object to a file:
Export is complete.
In the receiving configuration, the import code turns out to be quite simple:
Moreover, if a 1C object with such an identifier already exists in the database at the time it is read from the file, the object returned by the ReadXML method will not be new (IsNew()=False), but it will contain the data obtained from the file; if there is no object with such an identifier, the object will be new (IsNew()=True), it will contain data from the file, and a reference to the new object will already be assigned to it.
