AntidotE

simplest Sales Invoice import from CSV

Jun 1st, 2024
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. pageextension 50000 "CSV Sales Invoice List" extends "Sales Invoice List"
  2. { actions { addlast(processing) { action("CSV ImportFromCSV") {
  3. ApplicationArea = All;
  4. Caption = 'Import From CSV';
  5. Image = Import;
  6. ToolTip = 'Import Sales Invoice';
  7. trigger OnAction()
  8. var
  9. SH: Record "Sales Header";
  10. SL: Record "Sales Line";
  11. CSVB: Record "CSV Buffer";
  12. InS: InStream;
  13. i, LineNo: Integer;
  14. DateVal: Date;
  15. DecVal: Decimal;
  16. begin
  17. if not UploadIntoStream('Select CSV File', InS) then exit;
  18. CSVB.LoadDataFromStream(InS, ',');
  19. for i := 2 to CSVB.GetNumberOfLines() do begin // Skip header
  20. if CSVB.GetValue(i, 2) <> SH."External Document No." then begin
  21. SH.Init();
  22. SH.Validate("Document Type", SH."Document Type"::Invoice);
  23. SH.Insert(true);
  24. SH.Validate("Sell-to Customer No.", CSVB.GetValue(i, 1)); // Customer
  25. SH.Validate("External Document No.", CSVB.GetValue(i, 2)); // InvoiceNo
  26. Evaluate(DateVal, CSVB.GetValue(i, 3)); // Date
  27. SH.Validate("Document Date", DateVal);
  28. SH.Modify(true);
  29. LineNo := 0;
  30. end;
  31. LineNo += 10000;
  32. SL.Init();
  33. SL.Validate("Document Type", SH."Document Type");
  34. SL.Validate("Document No.", SH."No.");
  35. SL.Validate("Line No.", LineNo);
  36. SL.Insert(true);
  37. SL.Validate(Type, SL.Type::Item);
  38. SL.Validate("No.", CSVB.GetValue(i, 4)); // Item
  39. Evaluate(DecVal, CSVB.GetValue(i, 5)); // Qty
  40. SL.Validate("Quantity", DecVal);
  41. Evaluate(DecVal, CSVB.GetValue(i, 6)); // Unit Price
  42. SL.Validate("Unit Price", DecVal);
  43. SL.Modify(true);
  44. end;
  45. end; } } addlast(Category_Process) { actionref("CSV ImportFromCSV_Promoted"; "CSV ImportFromCSV") { } } } }
Advertisement
Add Comment
Please, Sign In to add comment