Combine Answers From Two Lists Into One

From HotDocs Wiki

Jump to: navigation, search

In some templates, you may want to combine lists of repeated variables into one. For example, you may 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 also want to remove any duplicate names. You can create a computation that uses the WHILE instruction to combine these lists.

This example shows how to combine a list of beneficiaries and fiduciaries into a single list of signers. The Beneficiary Information dialog is repeated in the first part of this script, and as answers are entered, their values are set to be used for Signer Name (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 Fiduciary Information dialog is repeated, HotDocs uses the WHILE instruction 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 Signer Information dialog.

The final part of the script makes sure that there are not any extraneous answers in the Signer Information dialog. For example, if the user enters five fiduciary names, but then removes two of them, this part of the script also removes those extra names from the list of signers.

Example

SET Num Var 1 TO 0 
 
REPEAT Beneficiary Information  
  INCREMENT Num Var 1  
  SET Signer Name[Num Var 1] TO Beneficiary Name 
END REPEAT
 
REPEAT Fiduciary Information  
  SET Num Var 2 TO 1  
  WHILE Num Var 2 <= Num Var 1 AND Fiduciary Name != Signer Name[Num Var 2]   
    INCREMENT Num Var 2  
  END WHILE   
  IF Num Var 2 > Num Var 1   
    INCREMENT Num Var 1   
    SET Signer Name[Num Var 1] TO Fiduciary Name  
  END IF  
END REPEAT  
 
WHILE COUNT( Signer Information ) > Num Var 1  
  SET Signer Name[COUNT( Signer Information )] TO UNANSWERED 
END WHILE
Num Var 1 A temporary Number variable used as a counter in the script. (See Create a Temporary Variable.)
Num Var 2 A temporary Number variable used as a counter in the script.
Beneficiary Information A repeated dialog containing a list of beneficiaries.
Beneficiary Name The beneficiary's name.
Fiduciary Information A repeated dialog containing a list of fiduciaries.
Fiduciary Name The fiduciary's name.
Signer Information A repeated dialog containing the combined list of names. Because its variable, Signer Name, is automatically SET in the script, this dialog should not be asked. Clear Ask Automatically at the Dialog Editor (Options tab) to prevent HotDocs from asking the dialog.
Signer Name A temporary Text variable repeated to insert all the names of the signers.