Writing back to a database

The biggest difference is that scripts in perspective run in a Gateway scope.

When you run some functions like system.db.runPrepUpdate in Gateway scope you will need to provide additional information. In this instance what database connection to run the query against.

When running in a vision client, if you don't provide the database connection, then the default connection is assumed. Thus the script works in a vision client, but not in perspective.

See the syntax section on this page in the manual:
https://docs.inductiveautomation.com/display/DOC81/system.db.runPrepUpdate

Notice how in the Gateway scope the database parameter is required and how in vision client scope the database parameter is optional (denoted by the [ ] surrounding it?

I will give you that it is a bit confusing that it also state that syntax will work in perspective session scope, in my experience it's best to assume that code will be running in the Gateway.

Get in the habit of always providing the database and you wont run into this particular problem.

1 Like