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

Copy all records from a list to a table

(0) ShareShare
ReportReport
Posted on by 15

Hi All,

I am trying to to create a payroll management application, I created a Salary Structure list where user can add different breakdown of allowances and their percentage that would make up for the gross pay. Now, I want to calculate the salary of each employee based on the amount supplied for the gross amount on the employee card (I have extended the employee card) so that I can display it on the employee card as a listpart. 

Sample Code (on Employee Card Extension):

Trigger

...

var
        salStructure: Record "Salary Structure";
        empSalary: Record "Employee Salary";
        counter: Integer;
    begin
        If empSalary.Get(Rec."No.") then begin
        salStructure.ID := 10000;
        If (salStructure.Find('=')) then begin
            repeat
                counter := 1;
                empSalary.Init();
                
             empSalary.ID := counter;
            empSalary."Emp. Name" := Rec.FullName();
            empSalary."Employee No." := Rec."No.";
            empSalary."Salary Name" := salStructure.Name;
            empSalary."Salary Description" := salStructure.Description;
            empSalary.Percentage := salStructure.Percentage;
            empSalary.Amount := (Rec."Gross Salary" / 100.0) * salStructure.Percentage;
            empSalary.Insert(true);

            Message('ID: %1, Name: %2, Percentage: %3, Amount: %4', counter, salStructure.Name, salStructure.Percentage, (Rec."Gross Salary" / 100 * salStructure.Percentage));
            counter := counter + 1;
            until (salStructure.Next() = 0);

        end;
end;
NOTE: The Message Dialog part works fine, shows all records and does the calculation correctly but the record is not getting inserted into table pass the first line in salStructure and then it throws error.
Salary StructureThis is the Salary Structure list
Sample Expected Result
Sample Expected Result but should have shown everything corresponding to Salary Structure
Error Screen
Error Screen.
I have the same question (0)
  • Suggested answer
    IB-29041624-0 Profile Picture
    1,191 Moderator on at

    Move this line:

        counter := 1;

    over your repeat loop.

    You are setting this value to one for every repeat and that is what cause the problem.

    so instead it should be

        counter := 1;

    repeat

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 607 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 421 Super User 2026 Season 2

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 375 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans