web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Codeunit to copy data from Sales price to custom sales price table

(0) ShareShare
ReportReport
Posted on by 55

Hi all,

Currently I am creating 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 a better code to the current codeunit, which will make it more efficient in copying the correct fields from table Temporary Sales Price to Sales price.

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;
}
I will provide more information if needed.
I have the same question (0)
  • Verified answer
    Marco Mels Profile Picture
    Microsoft Employee on at

    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.

  • Verified answer
    YUN ZHU Profile Picture
    102,908 Super User 2026 Season 2 on at

    Hi, I don't know if your table structure is the same as the original one, you can try the following two methods.

    Record.Copy(Record [, Boolean]) Method

    https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/record/record-copy-method

    Record.TransferFields(var Record [, Boolean]) Method:

    https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/record/record-transferfields-table-boolean-method

    Hope this helps.

    Thanks.

    ZHU

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 572 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 331 Super User 2026 Season 2

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 330 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans