0

Loop error / syntax

Hi all, this piece of code is adding summing up multiple times:

let me := this;
for i in select Pupil do
let myInvoice := (create Invoice);
myInvoice.(InvoiceDate := now());
myInvoice.('Invoice Amount' := sum((select Pupil).i.'Pupil Attendance Detail'.'StuChg £'));
myInvoice.(Pupil := i.Id)
end

for example, if I have 5 students, it sums up all of the values 5 times, it's probably an easy solve but it's not jumping out at me.

Thanks in advance

2 replies

null
    • Sean
    • 4 yrs ago
    • Reported - view

    Try this for the sum...

     

    myInvoice.('Invoice Amount' := sum(i.'Pupil Attendance Detail'.'StuChg £');

     

    The pupil table is already selected by the for-loop.

    • Grow Tuition
    • Sarah_CollinsHawthorne
    • 4 yrs ago
    • Reported - view

    Perfect - thank you so much!