Examples: Getting and setting environment variables

  1. This example converts a number to text and saves it as an environment variable.
    ENVIRONMENT OrderNumber := @Text(NewOrderNumber);

    These formulas are equivalent.

    @Environment("OrderNumber"; @Text(NewOrderNumber);
    @SetEnvironment("OrderNumber"; @Text(NewOrderNumber);
  2. This example retrieves the value of an environment variable, converts it to a number, and stores it in a local variable.
    OldOrderNumber := @TextToNumber(@Environment("OrderNumber"));
  3. This example is for a Computed when composed field. The formula maintains an environment variable named OrderNumber. When a new document is created, the formula retrieves the environment variable and increments it by 1. This algorithm does not work for databases that are replicated -- the database must exist on a single server or workstation and the formula must run on that same machine.
    OldOrderNumber := @Environment("OrderNumber");
    NewOrderNumber := @TextToNumber(@If(OldOrderNumber = ""; "0"; OldOrderNumber)) + 1;
    ENVIRONMENT OrderNumber := @Text(NewOrderNumber);
    NewOrderNumber;
  4. The first formula is run once by each sales person. This formula prompts for the sales area and makes it the value of an environment variable named SalesArea. In the form for the sales documents, you make the second formula the default value formula for the SalesArea field. This formula retrieves the value of the environment variable. The salesperson does not need to enter the sales area for each new document, and neither is a particular sales area hard-coded into the default value formula.
    ENVIRONMENT SalesArea := @Prompt([OkCancelList]; "Sales Area"; "What is your sales area?"; "Central"; "East" : "Central" : "West");
    @Environment("SalesArea");