Options

Get Purchase Price into Purchase Order Lines

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

Comments

  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,503
    Did you retrieve PurchLine record before your code?
    If you otherwise you can also use Rec. instead of PurchLine.
  • Options
    ccernatccernat Member Posts: 12
    used rec also. isnt working. is unbelivable.
  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,503
    can you show the modified code and where exactly did you write the code?

    Do you have record with those filters?
  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,503
    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 use
  • Options
    ccernatccernat Member Posts: 12
    good idea!! in a sec will try. tks.
  • Options
    ccernatccernat Member Posts: 12
    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.
  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,503
    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.
  • Options
    ccernatccernat Member Posts: 12
    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;
  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,503
    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.
  • Options
    ccernatccernat Member Posts: 12
    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!
  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,503
    and now remove all filters expect buy from vendor no. and try
  • Options
    ccernatccernat Member Posts: 12
    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;
  • Options
    ccernatccernat Member Posts: 12
    are you able to emulate this situation on your test db, pretty pretty pls?!
  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,503
    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 value
  • Options
    ccernatccernat Member Posts: 12
    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!
Sign In or Register to comment.