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
0
Comments
If you otherwise you can also use Rec. instead of PurchLine.
-Mohana
http://mohana-dynamicsnav.blogspot.in/
https://www.facebook.com/MohanaDynamicsNav
Do you have record with those filters?
-Mohana
http://mohana-dynamicsnav.blogspot.in/
https://www.facebook.com/MohanaDynamicsNav
Try to get the value from header and use
-Mohana
http://mohana-dynamicsnav.blogspot.in/
https://www.facebook.com/MohanaDynamicsNav
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.
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.
-Mohana
http://mohana-dynamicsnav.blogspot.in/
https://www.facebook.com/MohanaDynamicsNav
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;
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.
-Mohana
http://mohana-dynamicsnav.blogspot.in/
https://www.facebook.com/MohanaDynamicsNav
tks alot! at least we have a result!
-Mohana
http://mohana-dynamicsnav.blogspot.in/
https://www.facebook.com/MohanaDynamicsNav
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;
I have written code at the end of No. Onvalidate trigger.
may be you have written before standard price calculation function and overwriting the value
-Mohana
http://mohana-dynamicsnav.blogspot.in/
https://www.facebook.com/MohanaDynamicsNav
tka again!