Pass parameter a record to function

bekiobekio Member Posts: 204
Hello everyone,

I have created a function in codeunit with parameter table Purchase Receipt Line.
At Purchase Receipt Line i have added a button that i pass rec as a parameter to this codeunit. And if i pass REC just with few records, it sends to codeunit more than one document.

// This is the code on Purchase Receipt Line - Button.

PurchReceiptLine.RESET;
PurchReceiptLine.INIT;
PurchReceiptLine.SETRANGE(PurchReceiptLine."Document No.","Document No.");
GetAdditionalCost.ImplementPrices(PurchReceiptLine);


Up to this point it is ok, it filter the PruchReceiptLine with that document that i am currently focused on Purchase Receipt.

// Code in codeunit
// Function ImplementPrices with RecPurchReceiptLine as parameter table:

Var Name DataType Subtype Length
No RecPruchReceiptLine Record Purch. Rcpt. Line


IF RecPruchReceiptLine.FINDFIRST THEN
REPEAT
IF RecPruchReceiptLine."Current Unit Price" <> RecPruchReceiptLine."New Sales Price" THEN
BEGIN
// Some code
END;
UNTIL RecPruchReceiptLine.NEXT=0;

At this point at table RecPurchReceiptLine are more than that document that i pas as record parameter to this function.

Any suggestion where i am wrong.

I have seen also the Sales Post Yes/No codeunit it is the same and it has also more than one record when it gets a parameter from Sales Order > Post function.


Thanks

Answers

  • krikikriki Member, Moderator Posts: 9,110
    You just need to put VAR in your function to true, so the filters are past.

    And here is some cleanup to your code:

    PurchReceiptLine.RESET; // no need for an INIT if you only do something if you have a record.
    PurchReceiptLine.SETCURRENTKEY("Document No.","Line no."); // best always put a SETCURRENTKEY. Just to make it clear
    PurchReceiptLine.SETRANGE("Document No.","Document No.");
    GetAdditionalCost.ImplementPrices(PurchReceiptLine);

    Up to this point it is ok, it filter the PruchReceiptLine with that document that i am currently focused on Purchase Receipt.
    // Code in codeunit
    // Function ImplementPrices with RecPurchReceiptLine as parameter table:
    Var Name DataType Subtype Length
    Yes RecPruchReceiptLine Record Purch. Rcpt. Line

    IF RecPruchReceiptLine.FINDSET THEN // NEVER use FINDFIRST + REPEAT-UNTIL
    REPEAT
    IF RecPruchReceiptLine."Current Unit Price" <> RecPruchReceiptLine."New Sales Price" THEN BEGIN
    // Some code
    END;
    UNTIL RecPruchReceiptLine.NEXT=0;

    PS: check also this:http://www.mibuso.com/howtoinfo.asp?FileID=22
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • bekiobekio Member Posts: 204
    Thanks kriki for your suggestions on this.
    I have found it to just mark this, and for that reason i have puted as solved this topic.

    Thanks again for your good advice.
Sign In or Register to comment.