
I have several courses and some people (theses both are Microsoft lists) each course has a limited number of participants. Those who wants to join the course are randomly chosen. gebKurs is a slot for each guy to book a course ist is from gebKurs1 to gebKurs6. If he gets a free slot in the course the course goes from gebKurs to zugKurs. When one does not get a free space the course goes from gebKurs to nowhere. I did it for the first course this way:
Set(schleifenindex;CountRows(Kurse));;
If(schleifenindex>0;Set(temp2;Last(FirstN(Kurse;1)).Kurs);; Set(temp3;LookUp(Kurse;Title=temp2));;
//Schüler zuweisen
Set(randomSchüler;FirstN(Shuffle(Filter(Schüler;gebKurs1=temp2 Or gebKurs2=temp2 Or gebKurs3=temp2 Or gebKurs4=temp2 Or gebKurs5=temp2 Or gebKurs6=temp2 Or gebKurs7=temp2 Or gebKurs8=temp2));temp3.maxTeilnehmer-temp3.actualTeilnehmer));;
ForAll(randomSchüler;If(ThisRecord.gebKurs1=temp2;Patch(Schüler;ThisRecord;{gebKurs1:""});If(ThisRecord.gebKurs2=temp2;Patch(Schüler;ThisRecord;{gebKurs2:""});If(ThisRecord.gebKurs3=temp2;Patch(Schüler;ThisRecord;{gebKurs3:""});If(ThisRecord.gebKurs4=temp2;Patch(Schüler;ThisRecord;{gebKurs4:""});If(ThisRecord.gebKurs5=temp2;Patch(Schüler;ThisRecord;{gebKurs5:""});If(ThisRecord.gebKurs6=temp2;Patch(Schüler;ThisRecord;{gebKurs6:""});If(ThisRecord.gebKurs7=temp2;Patch(Schüler;ThisRecord;{gebKurs7:""});If(ThisRecord.gebKurs8=temp2;Patch(Schüler;ThisRecord;{gebKurs8:""})))))))));;
Patch(Schüler;ThisRecord;{gebStunden:ThisRecord.gebStunden-temp3.Stunden};{zugStunden:ThisRecord.zugStunden+temp3.Stunden});;If(IsBlank(zugKurs1);Patch(Schüler;ThisRecord;{zugKurs1:temp2});If(IsBlank(zugKurs2);Patch(Schüler;ThisRecord;{zugKurs2:temp2});If(IsBlank(zugKurs3);Patch(Schüler;ThisRecord;{zugKurs3:temp2});If(IsBlank(zugKurs4);Patch(Schüler;ThisRecord;{zugKurs4:temp2});If(IsBlank(zugKurs5);Patch(Schüler;ThisRecord;{zugKurs5:temp2});If(IsBlank(zugKurs6);Patch(Schüler;ThisRecord;{zugKurs6:temp2});If(IsBlank(zugKurs7);Patch(Schüler;ThisRecord;{zugKurs7:temp2});If(IsBlank(zugKurs8);Patch(Schüler;ThisRecord;{zugKurs8:temp2}))))))))));;
//Schüler abwählen
Set(randomSchüler;Filter(Schüler;gebKurs1=temp2 Or gebKurs2=temp2 Or gebKurs3=temp2 Or gebKurs4=temp2 Or gebKurs5=temp2 Or gebKurs6=temp2 Or gebKurs7=temp2 Or gebKurs8=temp2));;
ForAll(randomSchüler;If(ThisRecord.gebKurs1=temp2;Patch(Schüler;ThisRecord;{gebKurs1:""});If(ThisRecord.gebKurs2=temp2;Patch(Schüler;ThisRecord;{gebKurs2:""});If(ThisRecord.gebKurs3=temp2;Patch(Schüler;ThisRecord;{gebKurs3:""});If(ThisRecord.gebKurs4=temp2;Patch(Schüler;ThisRecord;{gebKurs4:""});If(ThisRecord.gebKurs5=temp2;Patch(Schüler;ThisRecord;{gebKurs5:""});If(ThisRecord.gebKurs6=temp2;Patch(Schüler;ThisRecord;{gebKurs6:""});If(ThisRecord.gebKurs7=temp2;Patch(Schüler;ThisRecord;{gebKurs7:""});If(ThisRecord.gebKurs8=temp2;Patch(Schüler;ThisRecord;{gebKurs8:""})))))))));;Patch(Kurse;temp3;{actualTeilnehmer:temp3.actualTeilnehmer-1});;Patch(Schüler;ThisRecord;{gebStunden:ThisRecord.gebStunden-temp3.Stunden})));;
This code does it for the first course. I need a loop now to do it for every course, but it does not work then... Can anyone please help me with that?
the problem: when I type it in for every single loop walk through it does not work. I think then I have to many lines of code... then powerapp can not be saved anymore... and the code is just black without colors... I really need help it is very important to get this.... Thanks a lot!!