Get Inspire insights from former attendees in our AMA discussion thread on Inspire Buzz. ACEs and other community members are on call all week to answer!

Engine Works

Under the hood of Alteryx: tips, tricks and how-tos.
GaryS
Alteryx
Alteryx

I recently had a client ask if there was anything in the Alteryx API to help figure out what the questions were in a wizard. Since the wizard is an xml file, we could just parse it with our favorite xml parser and look for the AlteryxDocument\Properties\RuntimeProperties\Questions tag. In fact, this is what I recommended to the client.

But surely there must be an easier way. After all, this is something that Alteryx needs to do in order to build the user interface when a wizard is run. Fortunately Ned provided me with the answer: the AlteryxDocument.dll.

 

The AlteryxDocument.dll is the .NET assembly that the Alteryx GUI uses to read and write Alteryx document files. It basically knows everything there is to know about an Alteryx module. For the purposes of this post, we'll focus on the question at hand – how to determine the questions in a wizard.

 

The main point of entry is through the Document class, which encapsulates all of the document reading and writing functionality. It has a constructor that takes the path to a module file:

 

Document module = new Document(path);

 

The next thing we need to know is what type of module this is. The Document class has a Type property that returns a DocumentType value. This value can be Module, Macro, or Wizard. In our case we are interested in only Wizard document types.

if (module.Type == Document.DocumentType.Wizard)
{
  ...
}

 

Now that we know our module is a wizard, we can get the list of questions out of it. The questions are exposed through the RuntimeSettings property. The Runtime class provides access to the information that needs to be handled when a module is run, and it has a Questions property that returns the list of wizard questions. There are several different types of questions that can be part of a wizard. When you click the Add button on the Wizard Design dialog, you can see the list of options.

 

Each type of question has a class associated with it: QuestionBoolean, QuestionBooleanGroup, QuestionDate, QuestionFileBrowse, QuestionFolderBrowse, QuestionLabel, QuestionLabelGroup, QuestionLink, QuestionListBox, QuestionNumericUpDown, QuestionRadioGroup, QuestionTab, and QuestionTextBox.

All of these classes derive from a base class called QuestionBase. This class provides support for all of the common question functionality, while each subclass provides the specific functionality for its type.

 

Several of the question types are not actually questions, but collections of other questions instead. QuestionBooleanGroup, QuestionLabelGroup, QuestionRadioGroup, and QuestionTab are all examples of this. In order for us to get the entire list of questions, we will need to recurse through these groups.

 

 

Fortunately, the QuestionBase class exposes two properties to help with this: HasChildren and Children.

 

The following code snipped demonstrates using these properties to fill a ListBox with the names of all of the questions. I've added a groupIndex property to add some indentation in order to highlight the nesting of questions within the question groups.

private void AddQuestionsToList(List questions, int groupIndex)
{
 StringBuilder spacer = new StringBuilder();

 for (int i = 0; i < groupIndex; i++)
 {
  spacer.Append("---");
 }

 foreach (QuestionBase question in questions)
 {
  QuestionsList.Items.Add(spacer.ToString() + question.LongDescription);
  
  if (question.HasChildren)
  {
   AddQuestionsToList(question.Children, groupIndex+1);
  }
 }
}

 

The results of running this on the MortgageCalculator sample wizard looks like this:

 

 

Comparing the results to the wizard GUI produced by Alteryx, it is easy to see that we have the information we need to build our own wizard interface. Other information, such as default value, can be obtained from the question subclasses.

 

If you would like to work with this interface, you can find the sample code (written in Visual Studio 2005) along with the AlteryxDocument.dll at the bottom of this post. Keep in mind that this version of the AlteryxDocument.dll is currently under development and is likely to be newer than the version that your install of Alteryx includes.

 

This means that if you write any module files through the interface, you will not be able to open them in Alteryx until the next version is released. Finally, your project will need to include a reference to the SrcUtils_DotNet.dll which you can find in your Alteryx 5.0 install folder.

 

Download the necessary files here.

Gary Schwartz
Director, Visualytics and Analytics Products

I've been with Alteryx since 2010 and have worked primarily on the Gallery and Server products. I've recently joined a new team focused on improving how Alteryx integrates with distributed computing platforms.

I've been with Alteryx since 2010 and have worked primarily on the Gallery and Server products. I've recently joined a new team focused on improving how Alteryx integrates with distributed computing platforms.