automatic filling of fields in the item journal line

kanikakanika Member Posts: 247
Hi experts!! NAV2017

In the Item Journal Line I have a new field "No Etiqueta", TableRelation Etiquetas (50000)

I need that when the field Etiqueta are validated the fields "Order No", "Document No" and "Item No"

are automatically filled getting the data from the Product Order Line table

My code:

No. Etiqueta - OnValidate()

Etiquetas.SETRANGE("No. Etiqueta","No. Etiqueta","No. Etiqueta");
ProOrdLine.SETFILTER("Item No.",Etiquetas."No. Referencia");
ProOrdLine.SETFILTER("Starting Date",'<=%1',WORKDATE);

"Posting Date":=WORKDATE;
"Item No.":=Etiquetas."No. Referencia";
"Order No.":=ProOrdLine."Prod. Order No.";
"Document No.":=ProOrdLine."Prod. Order No.";

But does nothing.

Best Answer

Answers

  • kanikakanika Member Posts: 247
    I also need that instead of the "Today" put "Workdate" in"Posting Date" but it does not work either
  • kanikakanika Member Posts: 247
    OOOOHHHHHHHH!!! YES

    SORRRYY

    TOO MANY HOURS WORKING

    WHAT A SHAME!!

  • kanikakanika Member Posts: 247
    this is the final code that works perfectly:

    Etiquetas.SETRANGE("No. Etiqueta",Rec."No. Etiqueta",Rec."No. Etiqueta");
    ProOrdLine.SETFILTER(Status,'Released');
    ProOrdLine.SETFILTER("Item No.",Etiquetas."No. Referencia");
    ProOrdLine.SETFILTER("Starting Date",'<=%1',WORKDATE);

    IF ProOrdLine.FINDLAST THEN BEGIN
    Rec."Posting Date":=WORKDATE;
    VALIDATE(Rec."Posting Date");
    Rec."Order No.":=ProOrdLine."Prod. Order No.";
    VALIDATE(Rec."Order No.");
    Rec."Document No.":=ProOrdLine."Prod. Order No.";
    VALIDATE(Rec."Document No.");
    Rec."Order Line No.":=ProOrdLine."Line No.";
    VALIDATE(Rec."Order Line No.");
    Rec."Item No.":=ProOrdLine."Item No.";
    VALIDATE( Rec."Item No.");
    Rec."Operation No.":='999';
    VALIDATE(Rec."Operation No.");
    Rec.Quantity:=Etiquetas.Cantidad;
    VALIDATE(Rec.Quantity);
    END;
    Thanks for all!! and Merry chrystmas
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    Just want you to make aware that the construct:
    Rec."Posting Date":=WORKDATE;
    VALIDATE(Rec."Posting Date");
    
    works slightly different than simple
    VALIDATE(Posting Date", WORKDATE);
    
    In the former case with separate linws with the assignment and the VALIDATE call you may miss some validation code.
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • AKAK Member Posts: 226
    How could that construct miss validation code? In both cases the field is validated with the same date and the code in the validate-trigger will be run. Or am I missing something?
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    edited 2017-12-22
    If the code inside the OnValidate trigger on a field includes
    IF xRec.Field <> Field THEN BEGIN...
    
    then the code inside the condition block bit will be always omitted if you validate the field like this:
    Field := 'Value';
    VALIDATE(Field)
    
    But if you validate like this
    VALIDATE(Field, 'Value')
    
    then the chances are that the validation code will be executed.
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • krikikriki Member, Moderator Posts: 9,112
    [Topic moved from 'NAV/Navision Classic Client' forum to 'NAV Three Tier' forum]

    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.