Get Purchase Price into Purchase Order Lines

ccernat
Member Posts: 12
Hello, guys!
Im a begginer in C/Al, not native english speaker. I dont know what is wrong in the code below, as Im trying to get the purchase price from the Purchase Price table into a field on the Purchase Order Lines, and i've put this code in the on validate section of the No field of the Purchase Line table. I also get from the Item table a piece index wich is working. But I cannot get the purchase price. What is wrong with the code?
//+CCVEVER01 - get piece index
IF Type=Type::Item THEN
"Piece Index":=Item."Indicele Piesei"
ELSE
"Piece Index":='';
//get purchase price
IF Type=Type::Item THEN
PurchPrice.RESET;
PurchPrice.SETRANGE("Item No.",PurchLine."No.");
PurchPrice.SETRANGE("Vendor No.",PurchLine."Buy-from Vendor No.");
PurchPrice.SETFILTER("Starting Date",'<=%1',PurchLine."Order Date");
PurchPrice.SETFILTER("Ending Date",'%1|>=%2',0D,PurchLine."Order Date");
IF PurchPrice.FINDLAST THEN BEGIN
"Purchase Price EUR" := PurchPrice."Direct Unit Cost"
ELSE
"Purchase Price EUR":=0;
//-CCVEVER01
Im a begginer in C/Al, not native english speaker. I dont know what is wrong in the code below, as Im trying to get the purchase price from the Purchase Price table into a field on the Purchase Order Lines, and i've put this code in the on validate section of the No field of the Purchase Line table. I also get from the Item table a piece index wich is working. But I cannot get the purchase price. What is wrong with the code?
//+CCVEVER01 - get piece index
IF Type=Type::Item THEN
"Piece Index":=Item."Indicele Piesei"
ELSE
"Piece Index":='';
//get purchase price
IF Type=Type::Item THEN
PurchPrice.RESET;
PurchPrice.SETRANGE("Item No.",PurchLine."No.");
PurchPrice.SETRANGE("Vendor No.",PurchLine."Buy-from Vendor No.");
PurchPrice.SETFILTER("Starting Date",'<=%1',PurchLine."Order Date");
PurchPrice.SETFILTER("Ending Date",'%1|>=%2',0D,PurchLine."Order Date");
IF PurchPrice.FINDLAST THEN BEGIN
"Purchase Price EUR" := PurchPrice."Direct Unit Cost"
ELSE
"Purchase Price EUR":=0;
//-CCVEVER01
0
Comments
-
Did you retrieve PurchLine record before your code?
If you otherwise you can also use Rec. instead of PurchLine.0 -
used rec also. isnt working. is unbelivable.0
-
can you show the modified code and where exactly did you write the code?
Do you have record with those filters?0 -
and probably the record is not inserted yet while validating the No. field so Buy-from Vendor No. is blank in Purchase Line.
Try to get the value from header and use0 -
good idea!! in a sec will try. tks.0
-
ok. isnt worlking. the code is written in the On Validate of the No. field in the Purchase Line table.
the code is supposed to get me two things: a field name Piece Index in the Item table - wich is working, and the field Direct Unit Cost from the Purchase Price table, based on vendor no and item no and starting and endind date. wich is isnt.
I got the Buy From vendor No from Purchase Header table. still not working.0 -
Did you set a message of Buy From Vendor No.? or debug?
Or comment the code of Vendor No. filter for a sec and try so that we can be sure that vendor no. is blank/wrong.0 -
code looks like this now ( still not working, i want to smash my head on the keyboard):
PurchPrice.RESET;
PurchPrice.SETRANGE("Item No.",Rec."No.");
//PurchPrice.SETRANGE("Vendor No.",PurchHeader."Buy-from Vendor No.");
//PurchPrice.SETFILTER("Starting Date",'<=%1',PurchHeader."Order Date");
//PurchPrice.SETFILTER("Ending Date",'>=%1',PurchHeader."Order Date");
//PurchPrice.SETFILTER("Ending Date",'%1|>=%2',0D,Rec."Order Date");
IF PurchPrice.FINDFIRST THEN BEGIN
Rec."Purchase Price EUR" := PurchPrice."Direct Unit Cost"
END ELSE
"Purchase Price EUR":=0;0 -
Just try this
PurchPrice.RESET;
PurchPrice.SETRANGE("Item No.",Rec."No.");
//PurchPrice.SETRANGE("Vendor No.",PurchHeader."Buy-from Vendor No.");
//PurchPrice.SETFILTER("Starting Date",'<=%1',PurchHeader."Order Date");
//PurchPrice.SETFILTER("Ending Date",'>=%1',PurchHeader."Order Date");
//PurchPrice.SETFILTER("Ending Date",'%1|>=%2',0D,Rec."Order Date");
IF PurchPrice.FINDFIRST THEN BEGIN
Message('%1',PurchPrice."Direct Unit Cost");
and see what is the result.0 -
it gives me the message with the correct result!!! then why the god damn field in the Purchase Line subform doenst update?
tks alot! at least we have a result!0 -
and now remove all filters expect buy from vendor no. and try0
-
this is madness. it doesnt work. code looks like this ( message is working, gives the correct result ), but field wont display. maybe it is something wrong with the field itself? what can it be?
PurchPrice.RESET;
PurchPrice.SETRANGE("Item No.",Rec."No.");
PurchPrice.SETRANGE("Vendor No.",PurchHeader."Buy-from Vendor No.");
//PurchPrice.SETFILTER("Starting Date",'<=%1',PurchHeader."Order Date");
//PurchPrice.SETFILTER("Ending Date",'>=%1',PurchHeader."Order Date");
//PurchPrice.SETFILTER("Ending Date",'%1|>=%2',0D,Rec."Order Date");
IF PurchPrice.FINDFIRST THEN BEGIN
MESSAGE('%1',PurchPrice."Direct Unit Cost");
Rec."Purchase Price EUR":=PurchPrice."Direct Unit Cost";
END;0 -
are you able to emulate this situation on your test db, pretty pretty pls?!0
-
It is working fine in my test db.
I have written code at the end of No. Onvalidate trigger.
may be you have written before standard price calculation function and overwriting the value0 -
thank you very much for the effort to help me. no, the code is written at the end of the No on validate trigger. well, maybe it is some minor little thing that i cant see it now. or maybe ill see it after 4 beers.
tka again!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