0

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.

2 replies

null
    • Ninox partner
    • RoSoft_Steven.1
    • 23 hrs ago
    • Reported - view

    Hi Fred,

    Could the issue be related to your custom recID field?

    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.recID or newRec.recID inside do as server doesn't behave as expected, especially for newly created records.

      • Fred
      • 13 hrs ago
      • Reported - view

       That is a very good memory. I am using a custom number field. I found that when manually recreating my DB depending on Id doesn't work if I have deleted records at all.

      Weird, I turned on line numbers but I don't see them.

      For line 21, the solution is I had a Trigger on create that was interfering with the script.

      For line 30, my solution is to add a for loop that fills in the data in its own do as server. Weird that I can't add the for loop inside the same do as server.

Content aside

  • 13 hrs agoLast active
  • 2Replies
  • 12Views
  • 2 Following