Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Answered

An Auto Job Queue to copy user inserted data from Sales price to a hidden custom sales price table

(0) ShareShare
ReportReport
Posted on by 55

Hi all,

I am trying to create a custom table Temporary Sales Price, its purpose is to autosave and write the data from this custom table Temporary Sales Price into the Sales price table of Business Central.

I have planned to use a CodeUnit for copying of field data from the custom Table to the standard Sales price table.

I have problems finding the correct code to do an autosave and to start a Job Queue automatically.

So far my CodeUnit Code is as below:

codeunit 51000 "Temp Sales Price"
{
    TableNo = "Sales Price";

    var

        CpySalesPrice: Record "Sales Price";



    trigger OnRun()
    begin
        CopyRows()
    end;

    // trigger OnRun()
    // var
    // Temp: Record "Temp Sales Price";
    // begin
    //     Temp.Init();
    //     Temp.Validate("Item No.", 'Placed in Job Queue');
    //     Temp.Insert(true);
    // end;


    procedure CopyRows()
    var
        FromTable: Record "Temp Sales Price";
        ToTable: Record "Sales Price";
    begin
        if FromTable.Find() then
            repeat
                ToTable."Item No." := FromTable."Item No.";           
                ToTable."Sales Code" := FromTable."Sales Code";
                ToTable."Currency Code" := FromTable."Currency Code";
                ToTable."Starting Date" := FromTable."Starting Date";
                ToTable."Unit Price" := FromTable."Unit Price";
                ToTable."Item No." := FromTable."Item No.";
                ToTable."Price Includes VAT" := FromTable."Price Includes VAT";
                ToTable."Item No." := FromTable."Item No.";
                ToTable."Allow Invoice Disc." := FromTable."Allow Invoice Disc.";
                ToTable."VAT Bus. Posting Gr. (Price)" := FromTable."VAT Bus. Posting Gr. (Price)";
                ToTable."Sales Type" := FromTable."Sales Type";
                ToTable."Minimum Quantity" := FromTable."Minimum Quantity";
                ToTable."Ending Date" := FromTable."Ending Date";
                ToTable."Coupled to CRM" := FromTable."Coupled to CRM";
                ToTable."Unit of Measure Code" := FromTable."Unit of Measure Code";
                ToTable."Variant Code" := FromTable."Variant Code";
                ToTable."Allow Line Disc." := FromTable."Allow Line Disc.";
                until FromTable.Next() = 0;
    end;
}
Wondering if there are similar solutions to automatic job queues for custom tables? my CopyRows Procedure could also use a shorter and more effective way of writing, as I have heard it might cause problems for later uses if data starts to get more complex and huge.
Thanks,
  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,091 Super User 2024 Season 1 on at
    RE: An Auto Job Queue to copy user inserted data from Sales price to a hidden custom sales price table

    Hi,

    You can try as per below

     procedure CopyRows()

       var

           FromTable: Record "Temp Sales Price";

           ToTable: Record "Sales Price";

       begin

           if FromTable.Find() then

               repeat

                 totable.init;

                 tottable.transferfields(FromTable);

                  tottable.insert();

                   until FromTable.Next() = 0;

       end;

  • Suggested answer
    Marco Mels Profile Picture
    Marco Mels on at
    RE: An Auto Job Queue to copy user inserted data from Sales price to a hidden custom sales price table

    Hello,

    We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist. If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    www.dynamicsuser.net/.../14

    I will open this up to the community in case they have something to add.

    Thanks.

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 Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans