Skip to main content

Notifications

Microsoft Dynamics NAV (Archived)

Moving records

Posted on by Microsoft Employee

I've created a Movement Worksheet and on a button click I want it to transfer all the records in the current worksheet into the new one. 

What's the most efficient way to do this? 

101.PNG

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Moving records

    Sorry for being Vague, issue has been resolved!

  • Verified answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,137 Super User 2024 Season 2 on at
    RE: Moving records

    Didnt get.. can you show us screenshot with issue..

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Moving records

    The soloution appears to work, thank you. On the Worksheet when you press the button, all the records from the new worksheet appear on the page, if you close and reopen it they dispear, as if it's showing the new journal, however the headings still show the old one. Is it possible to prevent this?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Moving records

    My apologies didn't see last line of your reply, ill try new soloution

  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,137 Super User 2024 Season 2 on at
    RE: Moving records

    Please remove the Line No. filter from above code..

    recShortageWorksheet2.SETRANGE("Line No.", recShortageWorksheet2."Line No.");

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Moving records

    It's still not finding the correct Line number and updating it with + 10000

     recShortageWorksheet2.RESET;

     recShortageWorksheet2.SETRANGE("Worksheet Template Name", 'MOVEMENT');

     recShortageWorksheet2.SETRANGE(Name, 'SHORTAGE');

     recShortageWorksheet2.SETRANGE("Location Code", 'TIOGA');

     recShortageWorksheet2.SETRANGE("Line No.", recShortageWorksheet2."Line No.");

     IF recShortageWorksheet2.FINDLAST THEN

       recShortageWorksheet2."Line No." := recShortageWorksheet2."Line No." + 10000

     ELSE recShortageWorksheet2."Line No." := 10000;

  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,137 Super User 2024 Season 2 on at
    RE: Moving records

    recShortageWorksheet2.SETRANGE("Worksheet Template Name", recShortageWorksheet2."Worksheet Template Name");

    recShortageWorksheet2.SETRANGE(Name, recShortageWorksheet2.Name);

    recShortageWorksheet2.SETRANGE("Location Code", recShortageWorksheet2."Location Code");

    I prefer to use Hardcoded values like MOVEMENT, SHORTAGE etc. instead of  recShortageWorksheet2.Name .

    please try and let us know.

    Please dont add Line no. filter in above code.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Moving records

    Taking this Code. I'm attempting to filter through the new record that the Records being transferred to. When trying to find the Last Line In the New record it's not finding the right value and trying to assign the new record to the same line No. How can I ensure it's finding the last line No. (I've taken it out of a repeat loop just to avoid infinite loops for now. )

    Rec.RESET;

    recShortageWorksheet.RESET;

    IF Rec.FINDSET THEN BEGIN

     // Transfer Records Into New Worksheet

     recShortageWorksheet.INIT;

     recShortageWorksheet.TRANSFERFIELDS(Rec);

     recShortageWorksheet."Worksheet Template Name" := 'MOVEMENT';

     recShortageWorksheet.Name := 'SHORTAGE';

     recShortageWorksheet."Location Code" := 'TIOGA';

     recShortageWorksheet."Line No." := recShortageWorksheet."Line No.";

     recShortageWorksheet2 := recShortageWorksheet;

     // Find the Last Line No.

     recShortageWorksheet2.RESET;

     recShortageWorksheet2.SETRANGE("Worksheet Template Name", recShortageWorksheet2."Worksheet Template Name");

     recShortageWorksheet2.SETRANGE(Name, recShortageWorksheet2.Name);

     recShortageWorksheet2.SETRANGE("Location Code", recShortageWorksheet2."Location Code");

     recShortageWorksheet2.SETRANGE("Line No.", recShortageWorksheet2."Line No.");

     IF recShortageWorksheet2.FINDLAST THEN

       recShortageWorksheet2."Line No." := recShortageWorksheet2."Line No." + 10000

     ELSE recShortageWorksheet2."Line No." := 10000;

     // Insert New Records into New Worksheet.

     recShortageWorksheet2.INSERT;

     DELETE;

    //UNTIL Rec.NEXT = 0;

    END;

    Thanks

  • Suggested answer
    Amol Salvi Profile Picture
    Amol Salvi 18,694 on at
    RE: Moving records

    [quote user="LewisTioga"]

    I Have this code so far. When it reaches the IF recShortageWorksheet2. FINDLAST THEN and the line below the value of the Name changes from SHORTAGE to the previous value 'AUTOMOVE' and is therefore inserting the new records into the old table. How do I resolve this?

    Rec.RESET;

    IF Rec.FINDSET THEN REPEAT

     // Transfer Records Into New Worksheet

     recShortageWorksheet.INIT;

     recShortageWorksheet.TRANSFERFIELDS(Rec);

     recShortageWorksheet."Worksheet Template Name" := 'MOVEMENT';

     recShortageWorksheet.Name := 'SHORTAGE';

     recShortageWorksheet."Location Code" := 'TIOGA';

     recShortageWorksheet."Line No." := recShortageWorksheet."Line No.";

     recShortageWorksheet2 := recShortageWorksheet;

     // Find the Last Line No.

     IF recShortageWorksheet2.FINDLAST THEN

       recShortageWorksheet2."Line No." := recShortageWorksheet2."Line No." + 10000

     ELSE recShortageWorksheet2."Line No." := 0;

      recShortageWorksheet := recShortageWorksheet2;

     // Insert New Records into New Worksheet.

     recShortageWorksheet.INSERT;

    UNTIL Rec.NEXT = 0;

    [/quote]

    You need to check this code as you are assigned recShortageWorkSheet2 to recShortageWorkSheet  after findlast and then you are inserting the record. Activate Debugger and check

  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,137 Super User 2024 Season 2 on at
    RE: Moving records

    recShortageWorksheet2 := recShortageWorksheet;

    // Find the Last Line No.

    IF recShortageWorksheet2.FINDLAST THEN

    so you are doing it to append the lines to new movement worksheet if there are any lines alreaddy exists. right?

    you can add filters instead of assigning the code.

    recShortageWorksheet2..SETRANGE("Worksheet Template Name",TO worksheet templte name);

    recShortageWorksheet2.SETRANGE(Name,TO worksheet name);

    recShortageWorksheet2.SETRANGE("Location Code",To Worksheet location);

    IF recShortageWorksheet2.FINDLAST THEN

    ...............

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans