Pass parameter a record to function

bekio
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
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
0
Answers
-
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=22Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
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.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions