Skip to main content

Notifications

Announcements

No record found.

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

How to transfer data from one table to another?

Posted on by Microsoft Employee

I am having a custom action on 2 different pages. 'event card' and 'event template', and on both actions the same page are getting opened (Eventcat.print) and on the template page, the template no and type will come automatically.  if I add the same template no in the event card. I am trying to copy all the records ie the 'type' and the 'template no.' into the event card., and now the template number and type are coming, but I have a 3-column code. in 'Event cat.print' Page. which is a lookup to another table(category print) and the user manually selects the code, but now I need to copy the 'code' to the event card .based on the event template number.

action("Event Cat. Print")
            {
                Caption = 'Event Cat. Print';
                ApplicationArea = all;
                Image = Accounts;
                trigger OnAction()
                var
                    Eventcategoryprint3: Record "Event Cat. Print" temporary;
                    Categoryprint: Record "Category Print";
                begin
                    Eventcategoryprint3.Reset();
                    Eventcategoryprint3.SetRange(No, REC."No.");
                    if not Eventcategoryprint3.FindFirst() then begin
                        Message('no');
                        Eventcategoryprint3.Init();
                        Eventcategoryprint3.Type := Eventcategoryprint3.Type::"Event";
                        Eventcategoryprint3.No := rec."No.";
                        Eventcategoryprint3.code := Eventcategoryprint3.code;
                        Eventcategoryprint3.Insert();
                    end;
                    if rec."Template No." <> '' then begin
                        Message('yes');
                        Eventcategoryprint3.Reset();
                        Eventcategoryprint3.SetRange(No, Rec."Template No.");
                        if not Eventcategoryprint3.FindFirst() then begin
                            Categoryprint.Reset();
                            Categoryprint.SetRange(code, Eventcategoryprint3.No);
                            IF not Categoryprint.FindFirst() THEN begin
                                Message('categoryprint%1', Categoryprint.code);
                                Eventcategoryprint3.Init();
                                Eventcategoryprint3.Type := Eventcategoryprint3.Type::Template;
                                Eventcategoryprint3.No := rec."Template No.";
                                Eventcategoryprint3.code := Categoryprint.code;
                                Eventcategoryprint3.Insert();
                            end;
                        end;
                    end;
                    Eventcategoryprint3.Reset();
                    page.Run(50001, Eventcategoryprint3);//
                end;

I am looking for a result like  these  but in my case 'code' [ A, B is blank

pastedimage1673873276898v1.png

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to transfer data from one table to another?

    yes, that is what happening now ....

    in both the pages same table used that is what the issue otherwise it will be easy to assign the value. On the same action i can make the modification or on the page level on afterget record will be more efficient?

    thanks for your help ,let me try to modify the code, Thanks you.

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,091 Super User 2024 Season 1 on at
    RE: How to transfer data from one table to another?

    Yes it will never work, because there is nothing with Categoryprint.findfirst, so it will not assign any value. You need to either generate a new code. or modify your code.

    Thanks.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to transfer data from one table to another?

    here the code will be the Eventcategoryprint3.code := Categoryprint.code; ,this is the possible one but no luck it doesnot the works,

    the code is coming from different table --> categoryprint.

    thats why iam trying to setrange with the template no and code , but  still its doesnot work

    pastedimage1673879600270v1.png

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,091 Super User 2024 Season 1 on at
    RE: How to transfer data from one table to another?

    Then How you want to generate the Code here?

    Thanks.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to transfer data from one table to another?

    Thanks for the reply Nitin Verma here the isssue is there is no record in the event header with code, so we cannot use like you suggested---> Eventcategoryprint3.code := Rec.code; //See this if this ok or Generate new one

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,091 Super User 2024 Season 1 on at
    RE: How to transfer data from one table to another?

    Please check the yellow one in your code.

    action("Event Cat. Print")
                {
                    Caption = 'Event Cat. Print';
                    ApplicationArea = all;
                    Image = Accounts;
                    trigger OnAction()
                    var
                        Eventcategoryprint3: Record "Event Cat. Print" temporary;
                        Categoryprint: Record "Category Print";
                    begin
                        Eventcategoryprint3.Reset();
                        Eventcategoryprint3.SetRange(No, REC."No.");
                        if not Eventcategoryprint3.FindFirst() then begin
                            Message('no');
                            Eventcategoryprint3.Init();
                            Eventcategoryprint3.Type := Eventcategoryprint3.Type::"Event";
                            Eventcategoryprint3.No := rec."No.";
                            Eventcategoryprint3.code := Rec.code; //See this if this ok or Generate new one
                            Eventcategoryprint3.Insert();
                        end;
                        if rec."Template No." <> '' then begin
                            Message('yes');
                            Eventcategoryprint3.Reset();
                            Eventcategoryprint3.SetRange(No, Rec."Template No.");
                            if not Eventcategoryprint3.FindFirst() then begin
                                Categoryprint.Reset();
                                Categoryprint.SetRange(code, Eventcategoryprint3.No);
                                IF not Categoryprint.FindFirst() THEN begin
                                    Message('categoryprint%1', Categoryprint.code);
                                    Eventcategoryprint3.Init();
                                    Eventcategoryprint3.Type := Eventcategoryprint3.Type::Template;
                                    Eventcategoryprint3.No := rec."Template No.";
                                    Eventcategoryprint3.code := Rec.code; //See this if this ok or Generate new one
                                    Eventcategoryprint3.Insert();
                                end;
                            end;
                        end;
                        Eventcategoryprint3.Reset();
                        page.Run(50001, Eventcategoryprint3);//
                    end;

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