Examples: Accessing the current document using formulas

  1. This example of a computed field value performs an arithmetic operation involving two other fields in the document. These fields must exist in the document, must be numeric, and must be initialized to a numeric value.
    TotalSales - CostOfSales
  2. This agent example performs an arithmetic operation on two fields in the current document, and assigns the result to a third field. The two referenced fields must exist; GrossSales can be new.
    FIELD GrossSales := TotalSales - CostOfSales;
    SELECT @All
  3. This agent example performs an arithmetic operation on two fields in the current document, and either assigns the value to a third field or sends a mail message. The first statement initializes GrossSales and is not necessary if you are certain the field already exists.
    FIELD GrossSales := 0;
    gs := TotalSales - CostOfSales;
    @If(gs > 0; @SetField("GrossSales"; gs); @MailSend("Ian Perron"; ""; ""; "No gross sales"; "Gross sales are zero or less for "; Subject));
    SELECT @All
  4. This column formula example evaluates to the value of KeyThought for documents that contain that field. If a document does not contain a KeyThought field, it "defaults" to the value of Topic.
    DEFAULT KeyThought := Topic;
    KeyThought
  5. This is another way of coding the preceding example.
    @If(@IsAvailable(KeyThought); KeyThought; Topic)
  6. This agent example deletes the GrossSales field.
    @If (@IsUnavailable(GrossSales); @Return(""); "");
    FIELD GrossSales := @DeleteField;
    SELECT @All
  7. This agent example calculates the GrossSales field, then displays the result and does not mark the document for update. As a result, no change takes place in the document in storage. The changes are saved if @DocMark is omitted or "@DocMark([Update])" is specified.
    FIELD GrossSales := TotalSales - CostOfSales;
    @Prompt([Ok]; "Gross sales for " + Subject; @Text(GrossSales));
    @DocMark([NoUpdate]);
    SELECT @All
  8. This example displays all the fields in the current document.
    @Prompt([OkCancelList]; "Fields"; "Fields in document"; ""; @DocFields);
    SELECT @All
  9. This window title formula displays "New Document" for a new document. For an existing document, the formula displays the Subject field and the number of responses.
    @If(@IsNewDoc; "New Document"; Subject + " with " + @Text(@Responses) + " response(s)")
  10. This view selection formula selects all documents except those for which the Form field contains "Profile" or "Log."
    SELECT !@Contains(Form; "Profile" : "Log")
  11. This view selection formula selects all documents for which the Subject field contains "acme" in any case, plus all their descendants.
    SELECT @Contains(@LowerCase(Subject); "acme") | @AllDescendants
  12. This form action formula displays the names and lengths of all attachments in a document, or "No attachments" if the document has no attachments.
    @If(@Attachments > 0; @Prompt([OkCancelList]; "Attachments"; "Attachment names and lengths"; ""; @AttachmentNames + " (" + @Text(@AttachmentLengths) + " bytes)"); @Prompt([Ok]; "Attachments"; "No attachments"))
  13. This onHelp event returns the name, row, and column of a table that is currently in focus.
    row := @GetFocusTable([CellRow]);
    @If(row = "0"; @Prompt([Ok]; "*No table*"; "Not in a table");
    @Do(
    column := @GetFocusTable([CellColumn]);
    name0 := @GetFocusTable([TableName]);
    name := @If(name0 = ""; "No name"; name0);
    @Prompt([Ok]; "*" + name + "*";
    "Row " + row + ", column " + column)))