In this blog post, we’ll walk you through the steps on how to synchronize a custom field between Dynamics 365 Business Central and CRM (Sales). This can be useful for keeping your data consistent across both systems, such as synchronizing Part Number and Detailed Description in Product or Item .
Prerequisites:
- Basic understanding of Dynamics 365 Business Central and CRM (Sales)
- Access to both systems
1. Ensure the custom field exists in both systems:
- In CRM:
- Identify the entity you want to add the custom field to (e.g., Product).
- Add the desired custom fields (e.g., Part Number, Detailed Description) to the chosen entity.
- In Business Central:
- Create the same custom fields with the same data type as in CRM.
2. Create a virtual table in Business Central:
- Use the AL Development tool (altpgen.exe) to generate a virtual table that represents the CRM entity you want to synchronize with (e.g., product).
-project:<Your AL project folder>
-packagecachepath:<Your AL project cache folder>
-serviceuri:<Microsoft Dataverse server URL>
-entities:product
-baseid:5348
- In Business Central, map the custom fields you created in step 1 to the corresponding fields in the virtual table.
- You have to extend the table then only keep the custom fields.
- Identify the appropriate code unit in Business Central based on your integration table mapping.
- In the code unit, subscribe to the relevant event triggered after the fields are added.
procedure InsertIntegrationFieldMapping(IntegrationTableMappingName: Code[20]; TableFieldNo: Integer; IntegrationTableFieldNo: Integer; SynchDirection: Option; ConstValue:
Text; ValidateField: Boolean; ValidateIntegrationTableField: Boolean)
var
IntegrationFieldMapping: Record "Integration Field Mapping";
begin
IntegrationFieldMapping.CreateRecord(IntegrationTableMappingName, TableFieldNo, IntegrationTableFieldNo, SynchDirection,
ConstValue, ValidateField, ValidateIntegrationTableField);
end;
- Define your custom field and add it to the event subscription.
action(customAction)
{
ApplicationArea = All;
Caption = ‘Custom action’;
Image = Price;
trigger OnAction()
var
DataverseProduct: Record “CRM Product”;
IntegrationFieldMapping: Record “Integration Field Mapping”;
begin
Message(‘Called’);
InsertIntegrationFieldMapping(‘ITEM-PRODUCT’, Rec.FieldNo(“Part No”), DataverseProduct.FieldNo(pcs_PartNumber), IntegrationFieldMapping.Direction::Bidirectional, ”, true, false);
InsertIntegrationFieldMapping(‘ITEM-PRODUCT’, Rec.FieldNo(“Anotation”), DataverseProduct.FieldNo(pcs_Annotations), IntegrationFieldMapping.Direction::Bidirectional, ”, true, false);
end;
}
- Make a change to the custom field value in one system (e.g., CRM).
- Wait for the synchronization to occur (may take up to 30 minutes).
- Verify that the change is reflected in the other system (e.g., Business Central).
Additional Notes:
Saving the changes in both systems may be necessary to trigger the synchronization.
It’s recommended to back up your field mapping before making any changes in Business Central.
By following these steps, you can easily synchronize custom fields between Dynamics 365 Business Central and CRM (Sales), ensuring that your data is consistent across both systems.
Reference: