Back to List
Placeholder | Replace With |
expression | An expression that results in true or false A True/False expression can be as complicated as it needs to be, but it must result in either true or false. For example, the expression yearsFrom( ChildBirthDate, today ) produces a number (the age of a person), not a true or false value—it is not a True/False expression. But the expression yearsFrom( ChildBirthDate, today ) > 17 can only result in true or false. It is a True/False expression. |
The while expression instruction allows you to repeatedly process (or loop through) an answer or set of answers until a certain condition is met, such as a certain answer is found or a limit is reached.
Before using the while instruction, you should understand the following:
In the following example, you want to create a list of signers in a will. Since the signers may include both beneficiaries and fiduciaries, you want to merge both lists into one. Because some fiduciaries may also be beneficiaries, you will want to remove any duplicate names. To loop through the list of fiduciaries, you will use the while instruction:
set SignerCount to 0
repeat BeneficiaryInformation
increment SignerCount
set SignerName[SignerCount] to BeneficiaryName
endRepeat
repeat FiduciaryInformation
set Lookup to 1
while Lookup <= SignerCount and FiduciaryName != SignerName[Lookup NU]
increment Lookup
endWhile
if Lookup > SignerCount
increment SignerCount
set SignerName[SignerCount] to FiduciaryName
endIf
endRepeat
In the first part of this script, the BeneficiaryInformation dialog is repeated, and as answers are entered, their values are set to be used for SignerName (which is the variable that will be repeated to insert all the names of the signers). Then, in the second part of the script, as the FiduciaryInformation dialog is repeated, HotDocs uses the while expression to test whether the name of the fiduciary is the same as any of the beneficiary names. If it is not, it will likewise be added to the SignerInformation dialog.
In the next example, you need to remove unwanted space characters from a user's account number. Here, the while instruction is used to repeat an answer, character by character, so that HotDocs can check to see if there are space characters in the answer. If there are, HotDocs removes them and rewrites the answer.
set CountIndex to 1
while CountIndex <= length( AccountNumber )
if mid( AccountNumber, CountIndex, 1 ) = " "
set AccountNumber to first( AccountNumber, CountIndex -1 ) + last( AccountNumber, length( AccountNumber ) - CountIndex )
else
increment CountIndex
endIf
endWhile
This script uses a temporary counter (CountIndex) to keep track of which character in the answer HotDocs is looking at. Any time the answer is repeated and HotDocs finds a space character, it removes it by concatenating the characters before and after the space character. HotDocs then makes sure that the new character it is now examining isn't a space character either. If it is not, HotDocs increments the temporary counter, moves to the next character, and repeats this process.
Back to List