Microsoft Dynamics 365 Business Central : How to Export and Import Data (Using XML Ports)
Hi, Readers.
This time, I would like to explore a different approach for importing or exporting data in Business Central using XML Port objects.
Contents
- Xml Ports overview
- Export Data
--------------------------------------------------------------------------------------
Xml Port Overview
--------------------------------------------------------------------------------------
An XMLport includes the following elements:
・An XMLport object
・An XMLport schema
・A Request page
・Properties, triggers, and code
XMLport object
XMLports facilitate the transfer of data between external systems and Dynamics 365 Business Central. Let's explore some key properties associated with them.
Source Code
xmlport 50100 "Export Items XMLport"
{
Caption = 'Export Items';
Format = VariableText;
Direction = Export;
TextEncoding = UTF8;
UseRequestPage = false;
FileName = 'ItemsViaXMLport.csv';
TableSeparator = '<NewLine>';
schema
{
textelement(Root)
{
tableelement(Integer; Integer)
{
XmlName = 'ItemHeader';
SourceTableView = SORTING(Number) WHERE(Number = CONST(1)); textelement(ItemNoTitle)
{
trigger OnBeforePassVariable()
begin
ItemNoTitle := Item.FieldCaption("No.");
end;
}
textelement(ItemDescTitle)
{
trigger OnBeforePassVariable()
begin
ItemDescTitle := Item.FieldCaption(Description);
end;
}
textelement(ItemTypeTitle)
{
trigger OnBeforePassVariable()
begin
ItemTypeTitle := Item.FieldCaption(Type);
end;
}
textelement(ItemInventoryTitle)
{
trigger OnBeforePassVariable()
begin
ItemInventoryTitle := Item.FieldCaption(Inventory);
end;
}
textelement(ItemBaseUnitofMeasureTitle)
{
trigger OnBeforePassVariable()
begin
ItemBaseUnitofMeasureTitle := Item.FieldCaption("Base Unit of Measure");
end;
}
textelement(ItemBaseCostisAdjustedTitle)
{
trigger OnBeforePassVariable()
begin
ItemBaseCostisAdjustedTitle := Item.FieldCaption("Cost is Adjusted"); end;
}
textelement(ItemUnitCostTitle)
{
trigger OnBeforePassVariable()
begin
ItemUnitCostTitle := Item.FieldCaption("Unit Cost");
end;
}
textelement(ItemUnitPriceTitle)
{
trigger OnBeforePassVariable()
begin
ItemUnitPriceTitle := Item.FieldCaption("Unit Price");
end;
}
textelement(ItemVendorNoTitle)
{
trigger OnBeforePassVariable()
begin
ItemVendorNoTitle := Item.FieldCaption("Vendor No.");
end;
}
}
tableelement(Item; Item)
{
XmlName = 'Item';
RequestFilterFields = "No.";
fieldelement(No; Item."No.")
{
}
fieldelement(Description; Item.Description)
{
}
fieldelement(Type; Item.Type) { } fieldelement(Inventory; Item.Inventory) { } fieldelement(BaseUnitofMeasure; Item."Base Unit of Measure") { } fieldelement(CostisAdjusted; Item."Cost is Adjusted") { } fieldelement(UnitCost; Item."Unit Cost") { } fieldelement(UnitPrice; Item."Unit Price") { } fieldelement(VendorNo; Item."Vendor No.") { }
}
}
}
}
pageextension 50100 ItemExt extends "Item List"
{
actions
{
addafter(History)
{
action(ExportItemsviaXMLport)
{
Caption = 'Export Items via XMLport';
Promoted = true;
PromotedCategory = Process;
Image = Export;
ApplicationArea = All;
trigger OnAction()
begin
Xmlport.Run(Xmlport::"Export Items XmlPort", false, false); end;
}
}
}
}
Hope this will help.
Thanks for reading.
Aditya