Pluralize Text Based on the Number of Database Records Returned

From HotDocs Wiki

Jump to: navigation, search


Sometimes you may want to pluralize text in the document based on whether two or more records are retrieved from a database table. For example, perhaps you are creating a list of customers. If there is only one customer in the list, you want the introductory text, Customer, to be singular. However, if there are two or more customers, you want this text to be plural—Customers.

Following are two examples of how you can accomplish this using either an expression or a Computation variable.

In the first example, HotDocs checks to see if the second iteration of the key variable that is linked to the database component is answered. (This means you must know that some particular database field will always be answered for any customer in the database.) The computation returns false if 0 or 1 customers are listed, or it returns true if there are 2 or more.

In the second example, the database component, Customers DB, is repeated. Each time a new record is selected, the counter is incremented. You can then use the result of Customer Count in the expression that merges (or doesn't merge) the plural -s.

Example

Example 1

ANSWERED( Customer Name[2] )

Example 2

SET Customer Count TO 0
REPEAT Customers DB
   INCREMENT Customer Count
END REPEAT
Customer Name This repeated dialog A Text variable that is linked to corresponding field in a database table.
Customer Count A temporary Number variable used as a counter in the computation. (See Create a Temporary Variable.)
Customer Count A repeating database component.