Update Allocate Append tool using XML
You’re running a process to select certain variables to be used within a model. You’ve built your process, but you’re getting tired of having to run it twice. Once to pull thousands of variables to check for relevance, and a second time with just the variables you want to include in the final model based on the tests you’ve run.
There’s good news! You can use the Action tool within the Interface toolset to update the Raw XML of the Allocate Append tool to dynamically select the variables you want to use, and it’s not as hard as you might think.
The first thing we need to do is find out what the XML code is for the variables we want to use, and the format it needs to be in for the Allocate Append tool to recognize it. You can enable the XML view from the User Settings menu (Options -> User Settings -> Edit User Settings). On the Advanced tab, there is a check box to “Display XML in Properties Window”:
Once you’ve checked the box, return to your Allocate Append tool, or any tool on your canvas, and you’ll see a new option on the right hand side that will allow you to see the XML code the tool is creating.
From here you can get the format you need for the XML code that we’ll pass into the macro to be created later.
Once you know the variables you want to use, you can use the variable name (code, not description) to build out the XML string as show above. If you select multiple variables, what you’ll notice is that they are each on their own line under the “<Variables>” tag in the XML code. The list you make must follow the same format:
In the sample workflow attached, you’ll see that I am using a Text Input tool to simulate the data stream that contains the fully compiled XML strings needed. As you will most likely see in your data, I have one variable per record. The problem is I need all of the variables in the same cell, on their own line. So how do we combine the records into one, and add a new line?
The answer is we use the Summarize tool. Within the Summarize tool we can use the Concat function to combine the XML strings into a single cell, and in the concatenate Properties section, we can indicate that we want to use a new line as the separator by typing in \n.
Now that the prep work is done, all we need to do is pass this new variable list into the Allocate Append tool through XML. This can be achieved with a simple Batch Macro. For the Control Parameter you want to use the Variable list that we just created. The Control Parameter gets connected to the Allocate Append tool which adds the Action tool as shown below.
In your Action tool, select the option to “Update Raw XML with Formula”, expand the options under Allocate Append until you see “Variables” and highlight that section. You’ll want to update the Inner XML, and the formula to use is the connection from the Control Parameter as shown below.
Once you have this set up, simply add your Macro Input (for your incoming data stream) and Macro Output (to feed back into your workflow) to complete the macro set up.
Return to your original workflow, insert your newly created Batch Macro and connect your inputs. Your variable list stream will feed into the ¿ input, and your main data stream to the other.
You’re now set to dynamically change the variables you are pulling! Simply run your process for selecting relevant variables, build your XML strings through the Formula tool and pass them into your macro.
View full article