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

Notifications

Announcements

No record found.

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
    Inge M. Bruvik Profile Picture
    1,111 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,135

#2
YUN ZHU Profile Picture

YUN ZHU 733 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 612

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans