Weird do as server issue
So I have the following code:
let t := this;
let rounds := switch leagueNum_calc do
case 2:
["1", "JO", "PO"]
default:
if SuperCup then
["Q", "S", "F1", "F2"]
else
["1", "2"]
end
end;
do as server
for loop1 in rounds do
if length(EventRoundAnalysis[round = loop1]) = 0 then
let newRec := (create EventRoundAnalysis);
newRec.(
Events := t;
round := loop1;
LinkID := formatJSON({
Event: t.recID
})
);
for subloop1 in ["rd", "F", "M"] do
let newERAStatRec := (create eraStats).(
EventRoundAnalysis := newRec;
level := subloop1;
LinkID := formatJSON({
EventRoundAnalysis: newRec.recID
})
);
void
end
end
end
end
The important parts are line 21 and 30. The JSON does not get created if I put the loop in a do as. If I let it run on the client side (no do as) the JSON gets created properly.
I can kind of understand that maybe the newRec might now work, but I don't understand why t doesn't work. It works to link on line 18.
Thanks for any help.
5 replies
-
Hi Fred,
Could the issue be related to your custom
recIDfield?If I remember correctly, you're using a custom number field populated by a Trigger on new record, rather than Ninox's built-in
Id?This might explain why linking the record works, while accessing
t.recIDornewRec.recIDinsidedo as serverdoesn't behave as expected, especially for newly created records. -
Hi Is is because rounds is defined outside the do as server, and then used inside, in which case it isn't recognised?
Regards John
-
I don't quite understand what the code is supposed to do. In any case, you want to create a JSON that always contains only one item – correct? Maybe you map the object first and then insert it into the formatJSON() function. I adjusted the table a bit for myself and both versions – yours and mine – work for me with do as server. Mirko
for loop1 in rounds do if length(EventRoundAnalysis[round = loop1]) = 0 then let newRec := (create EventRoundAnalysis); let objLoop1 := {} setItem(objLoop1, Event, t.recID) newRec.( Events := t; round := loop1; LinkID := formatJSON(objLoop1) );
Content aside
- 2 hrs agoLast active
- 5Replies
- 33Views
-
4
Following
