Sort a Repeated Dialog

From HotDocs Wiki

Jump to: navigation, search

When users enter a list of answers in a repeated dialog, you can sort the answers in ascending or descending order when they are merged into the assembled document. (Use the ASCEND and DESCEND instructions.) However, you may also want the answers to appear in the same order when they are viewed in the interview. For example, if an answer file already contains a list of attorney names, displaying those names in alphabetical order in the interview would make it easier for the user to know whether all names are listed or not.

To make sure answers are listed in the correct order in a dialog, users can either enter the answers in the correct order from the start, or you can add a script link dialog element to the repeated dialog that users can click to automatically sort their answers. Using this method, the answers will actually be sorted in the dialog instead of just sorted at the time answers are included in the assembled document. Likewise, the answers are sorted in the answer file.

Example

Note: The following computation script uses REPEAT instructions for two separate dialogs, which means it cannot be included or run from a repeated dialog. For example, if you add it to the repeated dialog you want to sort, HotDocs will return an error message because one dialog is not inserted in the other. To avoid this problem, you can create a third, non-repeated dialog for the script link button. In addition, you can insert the repeated dialog you want to sort into the non-repeated dialog using the Spreadsheet on Parent style, thus making the repeated dialog appear on the same dialog as the sorting button. Once you have created the Computation variable, you can assign it to a script link dialog element.
//Clear the temporary repeated dialog.
REPEAT Temp Repeat Dialog
  SET Temp Text TO UNANSWERED
  //Repeat the previous line for each variable in the dialog.
END REPEAT
 
//Copy answers to the temporary repeated dialog.
REPEAT Repeat Dialog
  SET Temp Text Var[COUNTER] TO Text Var
  //Repeat the previous line for each variable in the dialog.
END REPEAT
 
//Copy answers back to repeated dialog in ascending order.
REPEAT Temp Repeat Dialog
  ASCEND Temp Text Var
  SET Text Var[COUNTER] TO Temp Text
//Repeat the previous line for each variable in the dialog.
END REPEAT
Variable Name Description
Repeat Dialog Any repeated dialog containing at least one variable, Text Var, to be sorted.
Text Var Any Text variable in Repeat Dialog. The computation sorts the dialog based on this variable.
Temp Repeat Dialog A temporary repeated dialog used in the sorting computation.
Temp Text Var A temporary Text variable used in the temporary repeated dialog, Temp Repeat Dialog. (See Create a Temporary Variable.) This variable corresponds to Text Var, which is used as the basis for sorting the dialog.