Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Engine Works

Under the hood of Alteryx: tips, tricks and how-tos.
fvilelabr
Alteryx Alumni (Retired)

 

Did you know, behind each Alteryx workflow and its construction blocks there is XML content? Don't you trust me? Ok, so please let's right-click on any .yxmd file and open it into a notepad.

 

This the XML behind an Alteryx workflow; contained there is all information about the process.


Image1.png

 


And it is possible to see the XML syntax behind each object inside a workflow as well. As this is not enabled by default, it's necessary to enable it.

 

Go to Options -> User Settings -> Edit User Settings:


Image2.png



After this, go to Advanced tab and enable the option "Display XML in Properties Window":

 

Image3.png



 

Now, click on a tool and select the second option in the configuration box on the left ( </> ), as shown below, and you are able to see the XML syntax of the tool:


Image3.1.png

 


And the good news is: Yes! We can alter the XML of a tool. It means we are able to alter the metadata of the pieces of a workflow, in a completely dynamic way, based on parameters and business rules criteria.

 

giphy

 

 

This is done by "Update Raw XML With Formula" option inside an Action Tool on the interface tab of your tool palette.

 

With this option, we are going to take our workflow to a new level!

 

Let's go to a practice case.

 

I have built a macro that identifies data patterns and masks (i.e.: disguises or camouflages) them:

 

  • Letters to "X"
  • Numbers to "9"
  • Whitespace to "W"
  • Symbols to "S"

 

Example:

ID Customer

ID Customer Masked

123-ABC/10

999SXXXS99

DF-10 Y6-B

XXS99WX9SX

ABC-10AB10

XXXS99XX99

 

 

Oh god! How did I do it? It's very easy. Just need to put a Formula Tool and add 4 regular expressions on the field you want to mask, using REGEX_Replace from the String Functions sub-menu, as seen below:

 

Image4.png

 

 

REGEX_Replace returns the string resulting from the specified RegEx pattern. So, using the first expression as an example, the function finds all letters (A to Z, upper or lower case) and replace each of them to an "X" value. Besides this expression, it will be applied to all others in order to replace numbers, whitespace, and symbols to a new value.

 

It works!

 

However, I want to let users choose which kind of data masking they need to apply in their data. From this point, the workflow is going to get interesting.

🙂

 

image5.png



Example -
Pay attention! Only letters and numbers were masked:

ID Customer

ID Customer Masked

123-ABC/10

999-XXX/99

DF-10 Y6-B

XX-99 X9-X

ABC-10AB10

XXX-99XX99

 

 

The original Formula Tool would apply all 4 expressions over the data and it would mask all components, right? So I need to alter this tool dynamically in runtime in order to create the specific expressions I need to use according to user-defined choices. In other words, "recreate" the Formula tool at run time. 🙂

 

It is in cases like this, we are able to use the option to change the metadata by editing its XML syntax.

 

So, let's have fun!

 

 

Part I: Editing the XML syntax of the tool

 

As we have seen prior, whenever we need to see the XML syntax behind a tool we must click on the tool and select the second option (</>) in the configuration area.

 

image6.pngimage7.png

 

As the XML syntax shows us that there are 4 original expressions in the Formula Tool. We need to alter this metadata in order to keep only the expressions according to the user-defined-choice.

 

When we put a Control Parameter tool this workflow automatically becomes a Batch Macro.  So, from this moment this macro waits to receive a parameter. This parameter will be our new XML syntax that will replace the current syntax (it will be explained later).

 

image8.png

 


Looking at the Action Tool, we can see 3 Action Types, in this case, we need to select "Update Raw XML with Formula." This allows us to alter the XML syntax of a tool.

 

image9.png

 



With this option selected, at the bottom of the configuration window there is an option to change the XML based on a formula, that is, it is as if we were telling Alteryx the following: "Please do not use this Formula as it was originally created, instead recreate it for me using this new metadata that I'm giving you now."

😉

 

image10.png

 

 

Alteryx is our friend so it fully understands that this Formula tool is now receiving a new XML code that came from the Control Parameter Tool and replaces the original metadata to this one. When running, it will already use the "new" Formula Tool.

 

Part II: Creating the new XML syntax

 

There is a workflow that will call the macro showed before. Basically this allows users to choose which kind of transformation they want to do in their data, using the ListBox tool. Based on this user-choice it will be replacing the XML syntax into the macro, which will run the correct masking formulas.

 

image11.png

 

 

The first step is to choose the mask pattern (1 or more) and the Field:

 

 

 

image12.pngimage13.png

 

 

After this, only the variables that will be used in the Formula's REGEX_REPLACE function go through the flow.

 

 

image14.png

 

 

In a Formula Tool there will be an XML code exactly the same as the original expression. However, this expression will be fully recreated using the parameter "From" and "To" coming from the workflow.

 

 

image15.png



It will create a different expression for each user-choice:

 

image16.png

 


Then, to create the XML syntax, it`s necessary to concatenate in a single line all of the expressions. We did it using a Summarize Tool:

 

image17.png

 

 

 

Once the new XML code is created, this field is passed as a parameter to the Batch Macro. Now, the Formula Tool inside this macro will be changed and it will execute only the new expressions:

 

image18.png

 



And this is the final result:

 

image19.png

 


This example shows how versatile Alteryx is. With this option, we are able to dynamically recreate tools in our workflow, change their parameters, or perform different approaches based on business criteria. There is no limit!


 

giphy

 

This macro can be found here.

Comments