Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

Inserting into same table

Posted on by 70

pastedimage1580899496413v1.png

Hello Team,As per this Image i want to insert same data in this table itself .Only i want to replace table 23 instead of 18.I have written below function.

LOCAL DimentionInsertVendor(_VendorPar : Record Customer)
DefaultDimension.RESET;
DefaultDimension.SETRANGE("No.",_VendorPar."No.");
DefaultDimension.SETRANGE("Table ID",18);
IF DefaultDimension.FINDSET THEN REPEAT
//DefaultDimension.INIT;
DefaultDimension."Table ID" := 23;
DefaultDimension."No." := _VendorPar."No.";
DefaultDimension.VALIDATE("Dimension Code");
DefaultDimension."Dimension Code" := DefaultDimension."Dimension Code";
DefaultDimension.VALIDATE("Dimension Value Code");
DefaultDimension."Dimension Value Code" := DefaultDimension."Dimension Value Code";
DefaultDimension.MODIFY;
UNTIL DefaultDimension.NEXT=0;

when this code is executed only 1st record with table ID 23 is inserted and remaining records are not inserted.Please provide some suggestions.Thanks

  • Suggested answer
    Nitesh bhoir Profile Picture
    Nitesh bhoir 70 on at
    RE: Inserting into same table

    Thank you so much @phogue for your help. It really work for me.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Inserting into same table

    Are you inserting or replacing? You're calling MODIFY in your code snippet.

    If you only want to modify, you shouldn't do it on the same variable you're looping towards, you'd want to replace it with the following:

    IF DefaultDimension.FINDSET THEN REPEAT

      DefaultDimension2 := DefaultDimension;

      //DefaultDimension.INIT;

      DefaultDimension2."Table ID" := 23;

      DefaultDimension2."No." := _VendorPar."No.";

      DefaultDimension2.VALIDATE("Dimension Code");

      DefaultDimension2."Dimension Code" := DefaultDimension."Dimension Code";

      DefaultDimension2.VALIDATE("Dimension Value Code");

      DefaultDimension2."Dimension Value Code" := DefaultDimension."Dimension Value Code";

      DefaultDimension2.MODIFY; // Do you want to MODIFY or INSERT?

    UNTIL DefaultDimension.NEXT=0;

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans