Omnis Technical Note TNJS0013Jan 2022

Variable References in Client-executed Methods

for Omnis Studio 10 or above
By Omnis Engineering

There are some subtle differences to the way variables are passed around in client-executed methods in Omnis Studio, as opposed to methods that are executed on the server. This is due to the fact that client-executed methods are running JavaScript code, and so are bound by the rules of that language.

  • In JavaScript, variables and method parameters are always passed by value. This means that a copy of the value of the variable is passed around.

This is easily understood for primitive data types, such as string, number, and boolean, but objects are slightly more nuanced, that is, anything that’s not a primitive, including Omnis Lists, Rows, Dates and Remote Objects.

Object-type variables

  • The value of an object variable is essentially a pointer to that object.

This means that it is cheap and efficient to pass objects around, but there are two important consequences:

  1. If you change some property of a passed object, it will change the property on the original object too.

  2. If you re-assign the whole variable of the passed object, you are replacing the pointer, so will not affect the original object.

In Omnis, this only comes into play when you are using local variables or parameters in a client-executed method.

Example 1

Calculate lRow1 as iRow
Calculate lRow2 as lRow1

# lRow1 & lRow2 are two separate local variables, but because they are object types, they are now pointing to the same object in memory (as one was assigned the value of the other).

Calculate lRow1.C1 as "TEST"

# Changing an aspect of lRow1 will now also affect lRow2. So setting column 1 of lRow1 to "TEST" also sets column 1 of lRow2.

Calculate lColValue as lRow2.C1

# lColValue is "TEST"

Example 2

Calculate lRow1 as iRow
Calculate lRow2 as lRow1

# lRow1 & lRow2 are two separate local variables, but because they are object types, they are now pointing to the same object in memory (as one was assigned the value of the other).

Calculate lRow1 as row("TEST")

# Because we have reassigned the whole lRow1 variable, it has created a new pointer as the value of lRow1, so is no longer pointing to the same object as lRow2.

Calculate lColValue as lRow2.C1

# lColValue is the original value of column 1 from iRow

   

Search Omnis Developer Resources

 

Hit enter to search

X