Building dynamic workflows with detour tools or updating XML
If you are familiar with macros and apps, there are times where you want the behaviour of the app to change based on the user input. An example of this is a batch macro which is used to make an API call, which in this example I am using the bing search API. Sometimes when you get the results back from the API there are multiple results, if you are only interested in the best match then you can filter this data to the first row of the data, however what if you want to give the user the option to choose to show all results or only the best match?
So to take you through this, let’s first take a look at how the macro would ordinarily be configured.
This is a fairly standard workflow for a batch macro allowing you to make multiple API calls for different search terms. The focus is going to be on the final filter before the macro output tool, at the moment the filter condition is [ResultID] = 0, which will then only output the best match from the API result.
Using detour tools
If the user wants to add in optionality to the workflow then a way that you might have been taught is to use a detour tool, which gives the option to ‘divert’ the workflow.
The detour tool has a simple configuration which allows the user to manually tick the checkbox to detour to the right, which in the example workflow would result in by-passing the filter and therefore getting all the results.
This can be further extended by using an interface tool allowing this to be set as part of the macro configuration.
Updating the XML
The other option to add in conditional logic to your workflow is to update the XML of the tool configuration. Hopefully if you are reading this you will have already discovered that an Alteryx workflow is actually an xml file and the tool behaviour is configured by modifying the xml. If you haven’t already then I would recommend updating your workflow settings to show the tool xml in the configuration pane (this feature is turned on via Options -User Settings – Edit User Settings – Advanced – Display XML in Properties Window)
Now we update the workflow from above to remove the detour tools.
Then the action tool is set to update the Raw XML. This will allow the interface tools to update the behaviour of the filter tool.
The formula specified here takes the input from the interface tool ([#1]), where when the check box is ticked it will evaluate to TRUE and when it is unchecked it will evaluate to FALSE. Then the rest of the logic of the IF statement, puts in a 1=1 into the filter tool, which is a TRUE statement therefore it will output all records, or it will put in the [ResultID] = 0 into the filter and therefore only output the best match.
Personally I really like the ability to update the XML as it gives a lot of new options in how the workflow will behave.