In this code, SalesLine is not filtered, so the code is wrong. You need to retrive the SalesLine linked to your Purchase Line (Rec), so here it’s missing something like:
SalesLine.SETRANGE(“Document Type”,SalesLine.”Document Type”::Order);
SalesLine.SETRANGE(“Purchase Order No”,Rec.”Document No.”);
SalesLine.SETRANGE(“Purchase Order Line No”,Rec.”Line No.”);
IF SalesLine.FINDFIRST THEN
Rec."Unit Cost" := SalesLine."Unit Cost";
Note that I’m not sure if the fields that link a Sales Line to a Purchase Line in your system are the two fields mentioned above, but it’s just to give you an idea.