HotDocs.Server.Answer Class

An Answer is the set of Values for a particular HotDocs variable. For example, the Answer for a non-repeated variable consists of a single piece of data (text string, number, date, or other information) stored in a single Value. The Answer for a repeated variable, however, consists of multiple Values—one for each time the variable is repeated.

There are several ways to iterate through the Values of an Answer. If you know the repeat indexes for the Value you want to retrieve, you can simply set the 0-based repeat indexes of the Answer to those indexes. Thus, if you want to retrieve the second Value of a simple repeated variable, you could set the Answer's repeat indexes to 1,-1,-1,-1 . (Unused indexes should be set to -1 .) Once these indexes are set, retrieving the Answer's Value will return the data stored in the Value with the specified repeat indexes.

You can also use the ValueIndexes property to retrieve a list of repeat indexes for each Value in an answer. This is useful when you want to find all of the Values in an Answer, but you do not know the repeat indexes ahead of time. For example, an Answer that contains 5 Values nested two levels deep might return a list of ValueIndexes like this:

  • 0,0,-1,-1
  • 0,1,-1,-1
  • 1,0,-1,-1
  • 2,0,-1,-1
  • 2,1,-1,-1

You can then iterate through this list, setting the Answer's repeat indexes and retrieving the corresponding Value with each iteration.

Namespace: HotDocs.Server
Assembly: HotDocs.Server in HotDocs.Server.dll

This class implements the following interfaces:

  • IDisposable: The class can be disposed.

  • IList: The class is a list of Value objects.

Methods

Method Description
Add This method adds a new Value to the Answer object.
Answer (Constructor) This constructor initializes a new instance of the Answer class.
Clear This method removes all values (Value objects) from the Answer.
Contains This method determines whether or not the Answer object contains a specific Value.
CopyTo This method copies the collection of Value objects from the Answer to an array, starting at a particular index.
Dispose This method is an implementation of the IDisposable.Dispose method that releases unmanaged resources held by an instance of the Answer class.
GetEnumerator This method returns an enumerator that iterates through the Answer object.
GetRepeatCount This method returns the number of Value objects at the specified repeat indexes.
IndexOf This method determines the index of a specific Value in the Answer object.
Insert Inherited from the IList interface, but not implemented.  

This method is inherited from the IList interface, but it is not implemented in the Answer class. It will throw a NotImplementedException if called.

Remove This method removes the first occurrence of a specific Value from the Answer.  
RemoveAt This method removes the Value at the specified index from the Answer.

Properties

Property Description
AnswerType [Read/Write] This property is a value from the ansType enumeration that indicates the answer type
AnswerTypeText [Read/Write] This property is a string value that indicates the answer type.
Count [Read-only] This property returns the number of values in an Answer object.
Item Returns the specified item from the Answer object.
Name [Read/Write] This property is the name (i.e., variable name) of the Answer.
RepeatCount [Read-only] This property is the number of repetitions of the Answer at the current level. For example, if a non-nested answer is repeated three times, this property would return 3. If a nested answer is repeated 4 times at the first iteration and 2 times at the next, this property would return either 4 or 2 depending on the current repeat indexes.
RepeatIndexes [Read-only] This property is a RepeatIndices object, which represents the current set of repeat indexes for the Answer. Since an Answer may contain any number of Values, the repeat indexes serve as a "pointer" to reference individual Values. For example, if you want to reference the second Value in of a simple repeated variable, set its repeat indexes to 1,-1,-1,-1.
Value [Read/Write] This property is the Value of the Answer. After setting the Answer's RepeatIndexes property to the individual value you want to retrieve, this property will return the designated Value's value property.
ValueIndexes [Read-only] This property returns an Nx4 dimension array containing repeat indexes for all Values contained in an Answer, where N is the number of Values and each row in the array represents the repeat index set for a particular Value. If an Answer is "unanswered," the return value is empty. This property allows an integration to easily learn the details of all repeated Values of an Answer, which would be much more difficult using other API methods.

The following Visual C# example creates a new AnswerCollection that contains a single Answer with three Values. The AnswerCollection is then saved to disk as a HotDocs Answer File.

 
public class ExampleCode
{
    static void Main()
    {
        // Create a new AnswerCollection
        using (HotDocs.Server.AnswerCollection ac = new HotDocs.Server.AnswerCollection())
        {
            // Create an Answer to represent the child name and add it to the AnswerCollection
            using (HotDocs.Server.Answer names = new HotDocs.Server.Answer())
            {
                names.Name = "Child Name";
                names.AnswerType = HotDocs.Server.Interop.ansType.ansTypeText;
                int cnt = 3;
                for (int i = 0; i < cnt; i++)
                {
                    // Create a new value for each child's name and add it to the Answer
                    HotDocs.Server.Value nameVal = new HotDocs.Server.Value();
                    nameVal.RepeatIndex1 = i;
                    nameVal.value = System.String.Format("Dave {0}", i); // all the children are named Dave, just like in the Dr. Seuss story
                    names.Add(nameVal);
                }
                ac.Add(names);
            }
            ac.Save(@"C:\temp\children.anx");
        }
    }
}

This example opens an existing answer file and iterates through its  Answers. The name of each Answer,  and the value of each Value, is written to the  console.

public class ExampleCode
{
    static void Main()
    {
        // Create an AnswerCollection and populate it with an existing answer file.
        HotDocs.Server.AnswerCollection ac = new HotDocs.Server.AnswerCollection();
        ac.Open(@"c:\temp\JohnDoe.anx");
         
        foreach (HotDocs.Server.Answer ans in ac)
        {
            System.Console.WriteLine(ans.Name);
            foreach (HotDocs.Server.Value val in ans)
            {
                System.Console.Write(" " +
                    val.RepeatIndex1.ToString() + "," +
                    val.RepeatIndex2.ToString() + "," +
                    val.RepeatIndex3.ToString() + "," +
                    val.RepeatIndex4.ToString() + ": ");
 
                if (val.value.GetType().IsArray)
                {
                    // This means the value is an array such as a select all that apply Multiple Choice value.
                    System.Object[] valArray = (System.Object[]) val.value;
                     
                    for (int i = 0; i < valArray.GetLength(0); i++)
                    {
                        System.Console.Write(valArray[i].ToString());
                        if (i < (valArray.GetLength(0) - 1))
                        System.Console.Write("|");
                        else
                        System.Console.WriteLine();
                    }
                }
                else
                    System.Console.WriteLine(val.value.ToString());
            }
        }
        ac.Dispose();
    }
}