In a client-server environment sometimes one needs to pass a variable from a client to a trigger method on the server. This can be done by using the VARIABLE TO VARIABLE command called from a client and executed on the server (The "Execute on Server" property is checked as shown below).
4D Server keeps a reference of all client processes, and when the trigger execution is invoked from one of the clients, the server executes the trigger in the same process as the client. Because of this, if you pass the "Current process" as a first parameter to "VARIABLE TO VARIABLE", the client variables in this method will be accessible from the trigger method.
For example:
Let's say we have a variable var1 on the client, and we want to access it's value from a trigger method and pass this value to var2. The variable var2 has been declared in the trigger method.
On the Client:
C_TEXT(varOnClient) varOnClient:="Hello World" VARIABLE TO VARIABLE(Current process; varOnServer; varOnClient) |
After running this method, the value of varOnServer will be "Hello World".
By turning on Execute on Server, this seems to imply that the server can pull a variable from a client. But the docs specifically state that:
“Intermachine” process communication, provided by the commands GET PROCESS
VARIABLE, SET PROCESS VARIABLE and VARIABLE TO VARIABLE, is possible from client to server
only. It is always a client process that reads or write the variables of a stored procedure.
What does work, is to set the varOnClient value on the client. Then pass it in as parameter to a SetVariableOnServer method... SetVariableOnServer(varOnClient)... where SetVariableOnServer has Execute on Server turned on and looks like this:
c_text($1)
varOnServer:=$1