Wednesday, July 3, 2019

NAV CAL - How to update or insert a record on a PO

UpdatePOLineToMatchAILine(AILine : Record "Advance Invoice Lines")
PH.SETRANGE("No.",AILine."PO Number");
ReleasePurchDoc.PerformManualReopen(PH);
IF PL.FIND('-') THEN BEGIN
  PL.SETRANGE("Document No.",AILine."PO Number");
  PL.SETRANGE("Line No.",AILine."PO Line");
  IF PL.FIND('-') THEN BEGIN
  //Modify existing PO Line
    //PL.VALIDATE("Unit of Measure Code",AILine."Invoice UofM");
    PL.VALIDATE(Quantity,AILine."Invoice Quantity");
    PL.VALIDATE("Direct Unit Cost",AILine."Invoice Unit Price");
  END ELSE BEGIN
  //Insert new PO Line
    PL.INIT;
    PL.VALIDATE("Document Type",PH."Document Type");
    PL.VALIDATE("Document No.",PH."No.");
    PL.VALIDATE("Buy-from Vendor No.",PH."Buy-from Vendor No.");
    PL.VALIDATE(Type,PL.Type::Item);
    PL.VALIDATE("No.",AILine."Item Number");
    PL.VALIDATE("Location Code",PH."Location Code");
    PL.VALIDATE("Unit of Measure Code",AILine."Invoice UofM");
    PL.VALIDATE(Quantity,AILine."Invoice Quantity");
    PL.VALIDATE("Direct Unit Cost",AILine."Invoice Unit Price");
    PL.INSERT;
  END;
END;
ReleasePurchDoc.PerformManualRelease(PH);

No comments:

Post a Comment