lengend

Untitled

Mar 13th, 2026
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VisualBasic 1.50 KB | Source Code | 0 0
  1. SheetName := ExcelBuffer.ItemBoxQuantitySheet(InStream);
  2.         if SheetName = '' then
  3.            exit;
  4.  
  5.         ExcelBuffer.Reset();
  6.         ExcelBuffer.DeleteAll();
  7.         ExcelBuffer.OpenBookStream(InStream, SheetName);
  8.         ExcelBuffer.ReadSheet();
  9.  
  10.         // 3. Find the last row to determine the loop length
  11.         if ExcelBuffer.FindLast() then
  12.             MaxRow := ExcelBuffer."Row No.";
  13.  
  14.         // 4. Loop through rows (Starting at 2 to skip header row)
  15.         for RowNo := 2 to MaxRow do begin
  16.             ItemNo := GetValueAtCell(RowNo, 1);
  17.             BoxQtyTxt := GetValueAtCell(RowNo, 2);
  18.  
  19.             // Convert text to decimal safely
  20.             if not Evaluate(BoxQty, BoxQtyTxt) then
  21.                 BoxQty := 0;
  22.  
  23.             // 5. Create the Item Card Comment
  24.             if ItemNo <> '' then
  25.                CreateItemComment(ItemNo, BoxQty);
  26.         end;
  27.  
  28.         Message('Item Comments imported successfully!');
  29.    end;
  30.  
  31.     local procedure GetValueAtCell(RowNo: Integer; ColNo: Integer): Text
  32.     begin
  33.         if ExcelBuffer.Get(RowNo, ColNo) then
  34.             exit(ExcelBuffer."Cell Value as Text");
  35.         exit('');
  36.    end;
  37.  
  38.     local procedure CreateItemComment(ItemNo: Code[20]; BoxQty: Decimal)
  39.     var
  40.         CommentLine: Record "Comment Line";
  41.         Item: Record Item;
  42.         NextLineNo: Integer;
  43.     begin
  44.         // Step A: Check if the item actually exists before adding a comment
  45.         if not Item.Get(ItemNo) then
  46.             exit;
Advertisement
Add Comment
Please, Sign In to add comment