Sure Marco. Here My XML port :
xmlport 50031 " Item Journal Import"
{
Direction = Import;
FieldDelimiter = '"';
FieldSeparator = ',';
Format = VariableText;
UseRequestPage = false;
schema
{
textelement(Root)
{
tableelement(Integer; Integer)
{
SourceTableView = sorting (Number);
AutoReplace = false;
AutoSave = false;
AutoUpdate = false;
XmlName = 'ItemJurnalImport';
textelement(PostingDate)
{
}
textelement(EntryType)
{
}
textelement(DocumentNo)
{
}
textelement(ItemNo)
{
}
textelement(LocationCodeIn)
{
}
textelement(LotNo)
{
}
textelement(QuantityIn)
{
}
textelement(UnitOfMeasure)
{
}
textelement(ExternalDocNo)
{
}
textelement(MachineCode)
{
}
textelement(PlantCode)
{
}
trigger OnBeforeInsertRecord();
begin
if LineNo > 0 then
InsertRecord();
LineNo := LineNo + 1;
end;
}
}
}
requestpage
{
}
trigger OnInitXmlPort();
var
ItemJournalLine: Record "Item Journal Line";
begin
ItemJournalLine.setrange("Journal Template Name", JournalTemplateName);
ItemJournalLine.SetRange("Journal Batch Name", JournalBatchName);
if ItemJournalLine.FindLast then
LineNo := ItemJournalLine."Line No."
else
LineNo := 0;
end;
local procedure InsertRecord();
var
ItemJnlLine: Record "Item Journal Line";
Item: Record Item;
ItemLotErr: TextConst ENU = 'Item %1 not found';
Lot: Record "Lot No. Information";
ItemNoLot: Code[20];
LocationCode: Code[20];
BinCode: Code[20];
ItemNoMismatchErr: TextConst ENU = 'Item No. of Lot %1 does not match Item No. in file %2';
NoItemNoErr: TextConst ENU = 'No Item No. specified in file';
MachineCodeCode: Code[20];
PlantCodeErr : Label 'Plant Code must not be blank.';
begin
IF PlantCode = '' then
error(PlantCodeErr);
if LotNo <> '' then
GetLotInformation(LotNo, ItemNoLot, LocationCode, BinCode);
ItemJnlLine.init;
ItemJnlLine."Journal Template Name" := JournalTemplateName;
ItemJnlLine."Journal Batch Name" := JournalBatchName;
ItemJnlLine."Line No." := LineNo;
Evaluate(ItemJnlLine."Posting Date", PostingDate);
ItemJnlLine.validate("Posting Date");
Evaluate(ItemJnlLine."Entry Type", EntryType);
ItemJnlLine.validate("Entry Type");
ItemJnlLine."Document No." := DocumentNo;
if(ItemNo <> '') and(ItemNoLot <> '') and(ItemNo <> ItemNoLot) then
error(ItemNoMismatchErr, ItemNoLot, ItemNo);
if ItemNoLot <> '' then
ItemJnlLine.Validate("Item No.", itemnolot)
else if itemno <> '' then
ItemJnlLine.Validate("Item No.", ItemNo)
else
error(NoItemNoErr);
if LocationCode <> '' then
ItemJnlLine.Validate("Location Code", LocationCode)
else
ItemJnlLine.Validate("Location Code",LocationCodeIn);
if BinCode <> '' then
ItemJnlLine.validate("Bin Code", BinCode);
if UnitOfMeasure <> '' then
ItemJnlLine.Validate("Unit of Measure Code", UnitOfMeasure);
evaluate(ItemJnlLine.Quantity, QuantityIn);
ItemJnlLine.Validate(Quantity);
if lotno <> '' then
CreateReservationEntry(ItemJnlLine,LotNo);
if ExternalDocNo <> '' then
ItemJnlLine.Validate("External Document No.", ExternalDocNo);
MachineCodeCode := MachineCode;
if MachineCodeCode <> '' then
ItemJnlLine.ValidateShortcutDimCode(4, MachineCodeCode);
IF PlantCode <> '' then
ItemJnlLine.VALIDATE("Shortcut Dimension 2 Code",PlantCode);
ItemJnlLine.insert;
end;
local procedure GetLotInformation(LotNo: Code[10]; var ItemNoLot: Code[20]; var LocationCode: Code[20]; var BinCode: Code[20]);
var
ItemLedgerEntry: Record "Item Ledger Entry";
BinContent: Record "Bin Content";
NoOpenLotErr: TextConst ENU = 'No open Item Ledger Entry for Lot No. %1';
begin
ItemLedgerEntry.SetRange("Lot No.", LotNo);
ItemLedgerEntry.SetRange(Open, true);
if not ItemLedgerEntry.FindFirst then
error(NoOpenLotErr, LotNo);
BinContent.setrange("Location Code", ItemLedgerEntry."Location Code");
BinContent.setrange("Item No.", ItemLedgerEntry."Item No.");
BinContent.SetRange(Default, true);
if BinContent.FindFirst then
BinCode := BinContent."Bin Code";
ItemNoLot := ItemLedgerEntry."Item No.";
LocationCode := ItemLedgerEntry."Location Code";
end;
local procedure CreateReservationEntry(PItemJnlLine: Record "Item Journal Line";LotNo:Code[20]);
var
ReservationEntry: Record "Reservation Entry";
ResEntryNo: Integer;
begin
ReservationEntry.FindLast;
ResEntryNo := ReservationEntry."Entry No.";
ResEntryNo := ResEntryNo + 1;
ReservationEntry.Init;
ReservationEntry."Entry No." := ResEntryNo;
ReservationEntry."Item No." := PItemJnlLine."Item No.";
ReservationEntry."Location Code" := PItemJnlLine."Location Code";
ReservationEntry.validate("Quantity (Base)",PItemJnlLine."Quantity (Base)" * -1);
ReservationEntry."Reservation Status" := ReservationEntry."Reservation Status"::Prospect;
ReservationEntry."Creation Date" := Today;
ReservationEntry."Source Type" := Database::"Item Journal Line";
ReservationEntry."Source Subtype" := 3;
ReservationEntry."Source ID" := PItemJnlLine."Journal Template Name";
ReservationEntry."Source Batch Name" := PItemJnlLine."Journal Batch Name";
ReservationEntry."Source Ref. No." := PItemJnlLine."Line No.";
ReservationEntry."Shipment Date" := PItemJnlLine."Posting Date";
ReservationEntry."Created By" := UserId;
ReservationEntry."Qty. per Unit of Measure" := PItemJnlLine."Qty. per Unit of Measure";
ReservationEntry."Lot No." := LotNo;
ReservationEntry."Item Tracking" := ReservationEntry."Item Tracking"::"Lot No.";
ReservationEntry.Insert;
end;
procedure SetJournal(PItemJnlLine: Record "Item Journal Line");
begin
JournalTemplateName := PItemJnlLine."Journal Template Name";
JournalBatchName := PItemJnlLine."Journal Batch Name";
end;
var
LineNo: Integer;
EntryNo: Integer;
JournalTemplateName: Code[10];
JournalBatchName: Code[10];
}