If a behavior needs information that can only be known at runtime, environment variables are the answer. You can reference environment variables in any server-side code (Business Object Behaviors, App Behaviors and Reusable Behaviors) by accessing "process.env.<name of environment variable>".
Here is an example that prepares the url of a page in the app:
if (!process.env.appUrl) {
console.error('Please specify the appUrl environment variable with the full path to the app.');
}
const suppliersUrl = process.env.appUrl+'/Suppliers';
It is a best practice to check that the environment variable is defined. In the example above, if it is not specified an error is output to the logs.
If the environment variable is vital to the application and the app should not be run without it, you can do this:
if (!process.env.appUrl) {
throw Please specify the appUrl environment variable with the full path to the app.'
}
const suppliersUrl = process.env.appUrl+'/Suppliers';
Setting Environment Variables During Development
Non-sensitive environment variables (appUrl for example) can be set in Settings + Environment Variables. Sensitive environment variables (passwords for example) can be set on the App Manager.
Setting Environment Variables in Runtime Environments
The method of setting environment variables in runtime environments depends on your deployment process and target environment. Check with your Dev/Ops specialists to see how to do it.