Orda code not running on server

I have some code that works fine under interpreted and compiled mode but does not activate when running under the server ap. It seems to ignore the For Each section. Any help would be much appreciated. Here is code:

<code 4D>
C_OBJECT(Tgpos;TDnB;Tadd;Tsub;Tgpos1)
//takes overall orders and eliminates 3*, cfall, all tr transfers, alfalfa and misc from selection almost be shipped and no 0 amount orders
Tgpos:=ds.orders.query(“dealercode#:1 and dealercode#:2 and load_sheet#:3 and variety#:4 and variety#:5 and status=:6 and amount#:7”;“c*@”;“cfall”;“tr@”;“30@”;“xx@”;“SHIPPED”;0)

//pulls up cdis and Cbean TR’s to find the offsetting dealer TR’s to add back in
For each (TDnB;ds.orders.query(“dealercode=:1 or dealercode=:2 and load_sheet=:3 and status=:4 and amount#:5 and variety#:6 and variety#:7”;“cdis";"cbean”;“tr@”;“SHIPPED”;0;“30@”;“xx@”))
$short:=Substring(TDnB.load_sheet;1;Length(TDnB.load_sheet)-1)

For each (Tadd;ds.orders.query("load_sheet=:1";$short))
	Tgpos.add(Tadd)
End for each 

End for each
</code 4D>

Hi,

so, the code is running on a server process?
Which 4D Version and which OS?

Yes, code is running under a server process.

4D v17 R5 and running under OSX 10.14.6

Alex,

First I would return the queries into an entity selection objects and loop through those objects. This also allows you to log the results of the query and verify there is actually some data there. If the query returns nothing the behavior will look like what you describe.

Next, do you need process variables for this? If you are using the execute on server property then the objects you declare will persist in memory. Usually that’s not an issue but could be a source unexpected content persisting. I would use locals for the manipulations you perform.

Most of the time I have a method that behaves differently with EOS it’s because there is something in the calling process, like a process or IP variable, that doesn’t exist in the server context. Encapsulating these methods by using only local vars within them is the best way to prevent this sort of issue.

You can always return whatever interesting data you come up with as $0. $0 can itself be an object like:
{ success: , data: {}, arrays: [], entity_selection: {}, … }