Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

Copy records from one table into another

Posted on by Microsoft Employee

HI! I have 4 tables: tab1header, tab1lines and tab2header, tab2lines. I want to create something like posting -  copy information from one table (tab1heder and lines) to tab2heder and lines, then delete order from 1table. I am not good at using filters and its issue difficult to me. How I can do it? Can I find similar code in standard solution?

*This post is locked for comments

  • Sathish C Profile Picture
    Sathish C 180 on at
    RE: Copy records from one table into another

    Hi bharath karunakaran,

    can you find out any error in the code. suggest me some alternate code for the same function

  • bharathkarunakaran Profile Picture
    bharathkarunakaran 475 on at
    RE: Copy records from one table into another

    Your are trying copy some records from one table to another right.

    By the way do you have something like header and lines part in it.

    Try to debug it and can use MESSAGE function to check where the error is coming out.

    thanks

    Warm regards

    bharathk

  • Sathish C Profile Picture
    Sathish C 180 on at
    RE: Copy records from one table into another

    qwsas.PNG

    This code is not working for me in line part 

  • bharathkarunakaran Profile Picture
    bharathkarunakaran 475 on at
    RE: Copy records from one table into another

    Sure it will work .Try the above thing.

    Thanks

  • bharathkarunakaran Profile Picture
    bharathkarunakaran 475 on at
    RE: Copy records from one table into another

    Hi Serege,

    You can also try to create a two forms in which form1 as header and lines as a subform and then insert a action command from toolbox.

    In the second form do the same process above except the action button.

    Note: You must link the form and subform and also you must write some code in the action command for the transfer function .

  • Suggested answer
    Tina Menezes Profile Picture
    Tina Menezes 2,576 on at
    RE: Copy records from one table into another

    Hi,

    You need to use Insert function and copy values from table 1 header and lines to table 2 header and lines something like below:

    Table2Header.INIT;

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

    ...//Do this for all fields

    Table2Header.INSERT;

    Table2Lines.INIT;

    Table2Lines.VALIDATE(Table2Lines.Field1,Table1Lines.Field1);

    ......//Do this for all fields

    Table2Lines.INSERT;

    //Now delete this record from first table

    Now do setrange to find this record in table 1 and use delete function

    Table1Header.DELETE;

    Table1Lines.DELETE;

    You can check following links for reference:

    https://msdn.microsoft.com/en-us/library/dd355219.aspx

    https://msdn.microsoft.com/en-us/library/dd355378.aspx

    https://dynamicsuser.net/nav/f/beginners/12538/how-to-add-new-record-in-a-simple-table

  • Suggested answer
    Amol Salvi Profile Picture
    Amol Salvi 18,694 on at
    RE: Copy records from one table into another

    Is transaction table and posting table fields are same . If yes then use TransferFields. Or write code for import data from one table to another.

  • Suggested answer
    Zaid Tariq Profile Picture
    Zaid Tariq 2,266 on at
    RE: Copy records from one table into another

    Hi, Can you let me know that which Tab1header field has relationship with the field in Tab1lines table?

  • Suggested answer
    RockwithNav Profile Picture
    RockwithNav 6,562 on at
    RE: Copy records from one table into another

    Why dont you try something by yourself and take some help from standard NAV code and then come back to us with your code.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans