how to flow data from one table to another?

mdsrmdsr Posts: 86Member
edited 2019-05-23 in NAV Three Tier
on click of action define on page data from line table go to table newly created table how to achive this.
any help?
code for this ?

Answers

  • mdsrmdsr Posts: 86Member
    Table2Header.INIT;

    Table2Header.VALIDATE(Table2Header.Field1,Table1Header.Field1);

    Table2Header.INSERT;
  • wolfskinwolfskin Posts: 69Member
    edited 2019-05-24
    Do you mean that you do not want to validate for each field?

    If structure of Table1 and Table2 are similar, you can use the TRANSFERFIELDS function to flow all matching fields in one record to another record.

    <<https://docs.microsoft.com/en-us/dynamics-nav/transferfields-function--record->>;

    You can see the example from Table 36 (Sales Header) and Table 112 (Sales Invoice Header).

    Sorry if I misunderstand.

    Thanks,
  • mdsrmdsr Posts: 86Member
    edited 2019-05-24
    @wolfskin thanks for information actually i want transfer data from prod order line table to my newly created table.which have different fields name with same datatype what is code in that case.
  • wolfskinwolfskin Posts: 69Member
    Refer to this code below.
    mdsr wrote: »
    Table2Header.INIT;

    Table2Header.VALIDATE(Table2Header.Field1,Table1Header.Field1);

    Table2Header.INSERT;

    I think you know how to assign value on field to another table. So, what is your problem?

  • mdsrmdsr Posts: 86Member
    i want to insert prod.order line table data with selected multiple item should inseert in my created table but only one item inserted though multiple item select on action of released prod. order
    here is code
    Send To QC - OnAction()
    RecProdOrdLine.RESET;
    //RecProdOrdLine.SETRANGE(RecProdOrdLine.Status,RecProdOrdLine.Status::Released);
    RecProdOrdLine.SETRANGE("Prod. Order No.","Prod. Order No.");
    RecProdOrdLine.SETRANGE("Item No.","Item No.");
    RecProdOrdLine.SETRANGE("Line No.","Line No.");
    IF RecProdOrdLine.FINDSET THEN 
      REPEAT
      BEGIN
      InhousePendingQCList.INIT;
      InhousePendingQCList."Production Order No.":=RecProdOrdLine."Prod. Order No.";
      InhousePendingQCList."Item No.":=RecProdOrdLine."Item No.";
      InhousePendingQCList.Location:=RecProdOrdLine."Location Code";
      InhousePendingQCList."Total Quantity":=RecProdOrdLine.Quantity;
      InhousePendingQCList."QC Quantity":=RecProdOrdLine."QC Quantity";
      InhousePendingQCList.INSERT;
     // MESSAGE(InhousePendingQCList."Production Order No.");
     InhousePendingQCList."Serial No.":=InhousePendingQCList."Serial No."+1;
       END;
      UNTIL RecProdOrdLine.NEXT=0;
     
    
    
  • ShaiHuludShaiHulud Posts: 45Member
    edited 2019-05-24
    The filter you're applying to RecProdOrdLine ends up picking only one (last selected) line, that's why it inserts only one line.
    You should replace:
    RecProdOrdLine.RESET;
    //RecProdOrdLine.SETRANGE(RecProdOrdLine.Status,RecProdOrdLine.Status::Released);
    RecProdOrdLine.SETRANGE("Prod. Order No.","Prod. Order No.");
    RecProdOrdLine.SETRANGE("Item No.","Item No.");
    RecProdOrdLine.SETRANGE("Line No.","Line No.");
    
    with
    CurrPage.SETSELECTIONFILTER(RecProdOrdLine);
    

    This will make sure that the code loops through currently selected (on screen, marked in blue) lines.

    Also, your last line in the loop
    InhousePendingQCList."Serial No.":=InhousePendingQCList."Serial No."+1;
    
    seems a bit disconnected from everything else - there's no setting of initial value of field "Serial No.", so it will always end up being InitValue (field property) + 1. And it comes AFTER your INSERT, so it will not be saved on the record.
    Arturas Kulsinskas
    NaviLogic
  • mdsrmdsr Posts: 86Member
    @ShaiHulud i have tried your suggestion but now it gives me following error

    Microsoft Dynamics NAV

    The Inhouse Pending QC List already exists. Identification fields and values: Serial No.='35'
    OK
  • ShaiHuludShaiHulud Posts: 45Member
    edited 2019-05-27
    That's what the last part of my message was about. "Serial No." is your primary key field, so you need to resolve that somehow by making sure it always has a unique value. If it's just a running number, then you could write a code like this on the OnInsert() trigger on the InhousePendingQCList table:
    OnInsert()
    "Serial No." := 1;
    IF InhousePendingQCList.FINDLAST THEN
      "Serial No." := InhousePendingQCList."Serial No." + 1;
    
    where InhousePendingQCList is a variable of type Record and subtype of the table name/No.

    Then on the code we talked about earlier you need to change
    InhousePendingQCList.INSERT;
    
    to
    InhousePendingQCList.INSERT(TRUE);
    
    This will trigger the above written code.

    However, two things to consider:
    • If the Serial No. really works like that, always incrementing by 1, you may consider renaming it to something more appropriate, like "Entry No."
    • If the Serial No. represents something different than just running number, then you might want to write different logic to handle that.
    Arturas Kulsinskas
    NaviLogic
  • mdsrmdsr Posts: 86Member
    still getting same error as previous
    added code in on insert of table also note that table is having only one key serial no. which is auto increment after adding data
  • ShaiHuludShaiHulud Posts: 45Member
    Sorry, forgot the "+1" on the insert code, should be
    OnInsert()
    "Serial No." := 1;
    IF InhousePendingQCList.FINDLAST THEN
      "Serial No." := InhousePendingQCList."Serial No." + 1;
    
    Arturas Kulsinskas
    NaviLogic
Sign In or Register to comment.