Commerce 365 is capable of processing additional order attributes. The most popular module to use for this, is the Amasty Order Attributes extension. https://amasty.com/order-attributes-for-magento-2.html
But you can also accomplish this by doing some custom programming.
Once these values have been imported in to Business Central, the only thing left to do is to write a bit of custom code to take care of handling these values. By default our software doesn’t know what you want to accomplish with the order attributes you created on the Magento side. The values will just be imported. You can see them on the staging order page. But from here some coding is need.
Below is an example of further processing such values.
Here we are going to use the Sales Order API (codeunit 11260734) to extract the order attributes values, project_code, comments, file_upload and req_delivery_date. And next we will bring all the values over to their corresponding fields on the sales order.
[EventSubscriber(ObjectType::Codeunit, Codeunit::"NC365 Staging Order Events", 'OnAfterCreateSalesDocument', '', true, true)]
local procedure StagingOrderEvents_OnAfterCreateSalesDocument(var StagingOrderHeader: Record "NC365 Staging Order Header")
var
SalesHeader: Record "Sales Header";
SalesLine: Record "Sales Line";
TempBlobHelper: Record "NC365 Blob Helper" temporary;
SalesOrderAPI: Codeunit "NC365 Sales Order API";
ProjectCode: Text[30];
RequestedDeliveryDateStr: Text[30];
RequestedDeliveryDate: Date;
Comments: Text[1000];
FilePath: Text[1000];
begin
if not SalesHeader.Get(StagingOrderHeader."Created Doc. Type", StagingOrderHeader."Created Document No.") then
exit;
ProjectCode := SalesOrderAPI.GetStagingOrderAttributeValue(StagingOrderHeader, 'project_code');
Comments := SalesOrderAPI.GetStagingOrderAttributeValue(StagingOrderHeader, 'comments');
FilePath := SalesOrderAPI.GetStagingOrderAttributeValue(StagingOrderHeader, 'file_upload');
//For now we'll add a fixed path to our website domain, so that we have a full path to create a proper link
FilePath := 'https://www.websitedomain.com/pub/media/amasty_checkout' + FilePath;
//The order attributes module returns a date time, we only need a date, so we are splitting and taking the first element.
RequestedDeliveryDateStr := SalesOrderAPI.GetStagingOrderAttributeValue(StagingOrderHeader, 'req_delivery_date').Split(' ').Get(1);
//Evaluate to convert string to date, and if that fails, we'll go for the default formula for delivery date calculation
if not Evaluate(RequestedDeliveryDate, RequestedDeliveryDateStr) then
RequestedDeliveryDate := CalcDate('+5D', Today);
//Convert our incoming text to BLOB
TempBlobHelper.Init();
TempBlobHelper.WriteAsText(Comments);
SalesHeader.Validate("Work Description", TempBlobHelper."Blob");
SalesHeader.Validate("Requested Delivery Date", RequestedDeliveryDate);
SalesHeader.Validate("Your Reference", ProjectCode);
SalesHeader.Modify(true);
SalesHeader.AddLink(FilePath, 'Web order file upload');
end;