You can use Server Wide Variables to supply environment-specific values to ServerSide ViewModels running on MDrivenServer, such as whether the server is production or which external target a job should use.
What Server Wide Variables do
A Server Wide Variable is a value configured in MDrivenServer and made available to a ServerSide ViewModel when that ViewModel runs on the server.
To receive a value, the ServerSide ViewModel must declare a variable with the same name as the Server Wide Variable. When the server runs the ViewModel, it finds the matching variable by name and supplies the configured value.
This pattern keeps environment-specific decisions outside the model. For example, a deployment can configure a Boolean named vIsProduction as true in production and false in a test environment. A server-side export job can then decide whether to export to the production target or avoid the export.
Configure a Server Wide Variable
- In the MDrivenServer administration interface, declare the Server Wide Variable.
- Give it a name that the ServerSide ViewModel will use.
- Set the value appropriate for this server environment.
- Click Submit to save the Server Wide Variables.
- In the ServerSide ViewModel, add a ViewModel variable with the same name.
- Use that ViewModel variable in the job's expressions or actions.
The name match is significant. For example, a server variable named vIsProduction is available to a ServerSide ViewModel variable also named vIsProduction. A variable named vProduction does not match it.
Use values in ServerSide ViewModels
When a ServerSide ViewModel runs on MDrivenServer, its Server Wide Pre EAL runs before the remaining job actions. Use this execution order when a job must prepare or evaluate environment-specific information before it performs its normal work.
For example, declare vIsProduction for a job that exports data:
| Location | Variable | Example value | Purpose |
|---|---|---|---|
| MDrivenServer Server Wide Variables | vIsProduction
|
true on the production server; false elsewhere
|
Defines the environment for server-side jobs. |
| ServerSide ViewModel | vIsProduction
|
Value supplied when the ViewModel runs | Lets job logic determine whether it may perform a production export. |
The job can use the value to hold back an export outside production, or to select a different external system for non-production execution. Keep the actual job setup and scheduling in the ServerSide ViewModel; see Documentation:Serverside actions.
Special variables
MDrivenServer recognizes the following variable names for server-side execution behavior.
| Variable | Type | Effect |
|---|---|---|
vServerRestartedTime
|
DateTime
|
Receives the time of the most recent restart caused by a model evolution or an external event that stopped the application. |
vSkipQueryAndSkipJob
|
Boolean
|
When it evaluates to true, the PS query is skipped for all jobs.
|
vSkipQueryAndSkipJob_<ServerSideViewModelName>
|
Boolean
|
When it evaluates to true, the PS query is skipped for the named ServerSide ViewModel job only.
|
Detect a restart with vServerRestartedTime
Declare vServerRestartedTime:DateTime when a job needs to know when MDrivenServer was last restarted. Compare this value with a time that your application has stored previously. This lets you run initialization work after a restart or record that a restart occurred.
For example, an initialization job can store its last execution time in SysSingleton.oclSingleton.LastTimeTheInitJobWasExecuted. It can then skip its PS query after it has already run for the current server start.
Run a job once after a restart
To apply the skip behavior to one ServerSide ViewModel, declare a Boolean ViewModel variable named:
vSkipQueryAndSkipJob_<ServerSideViewModelName>
Replace <ServerSideViewModelName> with the name of that ServerSide ViewModel. Set the variable so that it is true when the job has already run since the latest restart.
For an initialization job, the Job EAL can use the following expression:
vSkipQueryAndSkipJob:=SysSingleton.oclSingleton.LastTimeTheInitJobWasExecuted>vServerRestartedTime
The job must also update SysSingleton.oclSingleton.LastTimeTheInitJobWasExecuted to DateTime.Now when the initialization work runs. On a later job cycle after the same restart, the stored execution time is newer than vServerRestartedTime, so the skip variable evaluates to true and the PS query is skipped.
Important behavior and checks
- Click Submit after changing Server Wide Variables. Unsaved values are not available to jobs.
- A ServerSide ViewModel receives a Server Wide Variable only when it declares a variable with the matching name.
vSkipQueryAndSkipJobaffects all jobs. Use the name-specificvSkipQueryAndSkipJob_<ServerSideViewModelName>form when only one job should be skipped.- A skipped PS query means the job does not query for the objects it would otherwise process. Ensure that this is the intended behavior before using either skip variable.
- If a server-side action does not process the expected objects, also check whether its OCLPS finds objects, whether its enable expression allows execution, and whether access groups permit the server-side ViewModel to run. See Documentation:Serverside actions.
