Synchronization of the Prepared Data
The synchronization of the prepared data can be started manually on the Process Data (BC501500) form, by an automation schedule, or as a result of the push notification. The following sections describe in order the general steps involved in the synchronization of the prepared data; the process diagram in the end of this topic shows the synchronization process in its entirety.
Beginning of the Synchronization
When the synchronization is started (see Item 1 in the process diagram), the system executes the ProcessSync() method of the PX.Commerce.Core.BCProcessData graph. The synchronization is performed in parallel threads. The parallel processing settings are specified in the PXParallelProcessingOptions object of the Statuses data view of the graph.
The ProcessSync() method creates an instance of the connector class that corresponds to the store with which the synchronization is performed. The method also specifies the information about the current operation in a PX.Commerce.Core.ConnectorOperation object and runs the implementation of the IConnector.Process() method (Item 2) available in the connector class.
For each entity that should be synchronized, the implementation of the IConnector.Process() method creates an instance of the processor class, initializes it with the information about the current operation, and runs its IProcessor.Process() method (Item 3), whose default implementation is available in the BCProcessorSingleBase<> class.
Retrieval of the Records for the Synchronization
- Retrieves the information about synchronized records from the
BCSyncStatus
database table (Item 4). - By calling BCProcessorSingleBase<>.GetBucketForExport() (Item 5a) or
BCProcessorSingleBase<>.GetBucketForImport() (Item 5b), pulls
the records that correspond to the entity through the APIs. These methods create a
bucket object for the export or import of records, respectively. The processor pulls the
records from MYOB Acumatica (Item 6a) by the value of the
LocalID
column of the table, and pulls the records from the external system (Item 6b) by the value of theExternID
column of the table.
Preprocessing of Data Before the Synchronization
If one entity has to be synchronized before the other—for example, before the synchronization of customer entities between an external system and MYOB Acumatica, you need to synchronize address entities—the processor synchronizes the entities that should be synchronized before the entity in the BCProcessorBase<>.ProcessPreProcessors() method (Item 7).
Exclusion of Possible Duplicate Records
The processor searches for the records that correspond to one another in MYOB Acumatica and the external system as follows:
- If the value in
ExternID
of theBCEntityStats
record is empty, searches for an external record that corresponds to the internal record in BCProcessorSingleBase<>.CheckExistingForExport() (Item 8a). - If the value in
LocalID
of theBCEntityStats
record is empty, searches for an internal record that corresponds to the external record in BCProcessorSingleBase<>.CheckExistingForImport() (Item 8b).Tip:The connector performs the following actions during the search:- Pulls records from the destination system by using a unique key (such as the customer's email address, the product name, or the order's external reference number) (Item 9a or 9b).
- If no records are found, continues with the synchronization of the new record, as described in the following section.
- If multiple records are returned from the destination system, throws an error and aborts the synchronization.
- If only one record is returned from the destination system, checks whether this
record has already been mapped to any other record by using the
BCSyncStatus
table (Item 10a or 10b) as follows:- If there is a record that has already been mapped to another record, throws an error and aborts the synchronization.
- If there are no mapped records, maps the currently processed record to the found record. The record will be synchronized as an existing record, as described below.
Control of the Synchronization Direction
- If both the external records and the internal records are changed (which is defined by their time stamps), the synchronization from the primary system to the secondary system is performed.
- If neither an external record nor an internal record is changed (which is defined by
time stamps), the synchronization from the primary system to the secondary system is
performed only if forced synchronization is being performed.Tip:Forced synchronization is performed if a user clicks Sync on the toolbar of the Sync History (BC301000) form.
- If only one time stamp is changed, the processor chooses the direction to synchronize changes from the changed record.
Then an implementation of the BCProcessorSingleBase<>.ControlDirection() method (Item 11) is called, in which you can add additional logic to the control of the synchronization direction.
When a direction is chosen, in the BCProcessorBase<>.EnsureSync()
method (Item 12), the processor locks the record so that it cannot be synchronized from the
other threads by updating the SyncInProcess
flag of the BCSyncStatus
table (Item 13). If
the record has been locked already by the other process, the connector aborts the operation
and proceeds to the processing of the next record.
Import of Records
- For the records that have been deleted, removes the related records in MYOB Acumatica in the BCProcessorBase<>.DeleteRelatedEntities() method.
- Maps the properties of the external object to the properties of the MYOB Acumatica object in BCProcessorBase<>.MapBucketImport() method.
- Applies the mappings that have been defined by the user on the Entities (BC202000) form in the BCProcessorBase<>.RemapBucketImport() method.
- In the BCProcessorBase<>.ValidateImport() method, validates the entity that is going to be saved to the MYOB Acumatica database to ensure that no required fields are left empty.
- Saves the data to the database in
BCProcessorSingleBase<>.SaveBucketImport() (Item 15a).Note:In the end of the implementation of the SaveBucketImport() method, you need to call the BCProcessorBase<>.UpdateStatus() method to update the time stamps and IDs of the synchronized records. For details, see Update of the Synchronization Status.
Export of Records
- For the records that have been deleted, removes the related records in the external system in the BCProcessorBase<>.DeleteRelatedEntities() method.
- Maps the properties of the MYOB Acumatica object to the properties of the external object in BCProcessorBase<>.MapBucketExport() method.
- Applies the mappings that have been defined by the user on the Entities (BC202000) form in the BCProcessorBase<>.RemapBucketExport() method.
- In the BCProcessorBase<>.ValidateExport() method, validates the record that is going to be saved to the external system to ensure that no required fields are left empty.
- Saves the data to the external system in
BCProcessorSingleBase<>.SaveBucketExport() (Item 15b).Note:In the end of the implementation of the SaveBucketExport() method, you need to call the BCProcessorBase<>.UpdateStatus() method to update the time stamps and IDs of the synchronized records. For details, see Update of the Synchronization Status.
Update of the Synchronization Status
In the BCProcessorBase<>.UpdateStatus() method (Item
16), the processor updates the BCSyncStatus
record (Item 17) with
the result of the operation as follows:
- If the synchronization was successful, the processor updates the record to reflect the
new time stamps and IDs.
PendingSync
is set tofalse
. - If the synchronization has failed, the processor updates the status to Failed, updates the error message and increments the number of failed attempts.
- If the synchronization of this record has failed more than the configured maximum number of attempts, the processor automatically assigns the Skipped status to the record.
SyncInProcess
flag of
the BCSyncStatus
table. The processor then saves all the changes to the
database.Synchronization of the Dependent Records
The processor synchronizes the entities that should be synchronized after the entity in the BCProcessorBase<>.ProcessPostProcessors() method (Item 18). If post-processing has failed, the synchronization of the current entity is not affected.