XMLPort in Business Central AL Programming

XMLPort Object

Dynamics 365 Business Central supports exporting and importing data through XMLports. In an XML format, data can be shared seamlessly across multiple computer systems. XMLports handle the details of how XML files are handled so that you do not have to worry about it.

An XMLport object must first be created before you can import or export data. The XMLport can be implemented as an object in a page or code unit to run it.

XMLPort Snippet

No alt text provided for this image

XMLPort - Important items

An XMLport has the following items

  1. An XMLport object
  2. An XMLport schema
  3. Request page
  4. Properties
  5. triggers
  6. code

XMLPort Properties

  1. Format: Used to set the formats of the source expression for various data types.

Possible input: XML, VariableText, FixedText

  1. Direction: Used to set the XmlPort to import, export, or import and export data in XML format.

Possible input: Import, Export, Both

3. TextEncoding: Used to specify the text encoding format to use when you use an XmlPort to export or import data as text.

Possible input: MSDOS, UTF8, UTF16, WINDOWS

4. UseRequestPage: Used to set whether a request page is presented to the user

Possible input: true/false

5. TableSeparator: Used to specify the table separator for a table.

Possible input: none, newline, CR/LF, CR, LF, TAB, Other strings

XMLPort Schema

Consist of

  1. A text element
  2. A text attribute
  3. A table element
  4. A field element
  5. A field attribute

XML Export

Find more about how to use XMLPort to export the file from the video


xmlport 50100 ExportItemsXmlPor
{
Format = VariableText;
Direction = Export;
TextEncoding = UTF8;
UseRequestPage = false;
TableSeparator = '';
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.")
{
}
}
}
}
}        

Hope you got an idea of how to use the XMLPort to export the data.

I will post another article related to BC Al programming.

Take care

要查看或添加评论,请登录

Dr. S. Gomathi的更多文章

社区洞察

其他会员也浏览了