Problem with if and else in a loop
Hey, i got a problem with my code:
do as server
for i in select Leads do
if i.Status = 2 then
for j in select Kunden do
if i.Nachname = j.Nachname then
i.(Status := 1);
else
let neuerKunde := (create Kunden);
neuerKunde.(Nachname := i.Nachname);
neuerKunde.(Vorname := i.Vorname);
neuerKunde.('E-Mail Ansprechpartner 1' := i.'E-Mail');
neuerKunde.(Ort := i.Ort);
neuerKunde.(PLZ := i.PLZ);
i.(Status := 1)
end
end
end
end
end
The first if-Statement works totally fine. The problem is, that in the second loop both conditions are executed.
To test the code i got two entries in the Leads table. One is similar to one in the Kunden table and one is not.
If i test it with the one that is similar, the status is changed to 1 and i got one new row in the Kunden table.
If i test it with the one that is not similar, the status is changed to 1 and i got two new records with the same values.
2 replies
-
I guess i found the error. Is there any expression to exit the loop?
-
Sadly there isn't an exit command. Since you only want to modify Leads records with a Status = 2, you can add that to your select so you can skip the first if/then.
do as server for i in (select Leads where Status = 2) do for j in select Kunden do if i.Nachname = j.Nachname then i.(Status := 1); else let neuerKunde := (create Kunden); neuerKunde.(Nachname := i.Nachname); neuerKunde.(Vorname := i.Vorname); neuerKunde.('E-Mail Ansprechpartner 1' := i.'E-Mail'); neuerKunde.(Ort := i.Ort); neuerKunde.(PLZ := i.PLZ); i.(Status := 1) end end end end
Content aside
- 1 yr agoLast active
- 2Replies
- 93Views
-
2
Following