community
cancel
Showing results for 
Search instead for 
Did you mean: 

Alteryx Designer Knowledge Base

Definitive answers from Designer experts.
Community v19.6

Looks aren't everything... But the latest Community refresh looks darn good!

Learn More

CS Macro Dev: Field Maps, Drop Downs, & the Select Tool Trick

Alteryx
Alteryx
Created on

 

This article is part of the CS Macro Development Series. The goal of this series is to communicate tips, tricks, and the thought process that goes into developing good, dynamic macros.

 

Many macros need to be especially dynamic to allow the user to select which field to use in a very complex process. Take the Make Grid tool for example. It asks the user to specify a spatial object field, and only carries that field through its calculations. What comes out of the tool are two new fields, GridName and Grid, and none of the original fields at all.

 

make grid browse.PNG

 

I set out to build a macro just like this tool, except to generate a hexagonal grid. I started by building a normal workflow that could do this process, and when I was ready to convert it to a macro, I realized that I wasn't sure of the best way to enable it to choose this field dynamically.

 

There are two main ways to get data into your macro. Here's a quick summary of how they work:

 

Field Maps

 

The Macro Input tool has a checkbox in its configuration that reads Show Field Map.

 

field map.PNG

 

If this is unchecked, then your macro won't do anything with the data - it will just stream in everything as is and trust that the stuff inside knows how to account for anything you throw at it.

 

If it is checked, then your macro will create drop down menus in its configuration window that will ask for the fields you have present in the Template Input. These drop down menus will let you select which fields to stream in to the macro in place of the ones in its template.

 

field map config.PNG

 

The field map needs all those drop downs to be filled out for it to do its thing, but if you want to make one of these inputs optional, just add (Optional) to the field name in your macro template.

 

optional.PNGoptional1.PNG

 

Advantages:

1.  Easy to set up! One checkbox and your template are all that's needed.

2.  Makes sure only mapped fields enter the macro. This is good when converting a workflow to a macro because you don't need to worry about every form the input data stream could be in. If your stream has other fields, they will get tacked on to the stuff coming out of the macro.

 

Drop Down

 

Drop Down menus are an alternative way you can bring fields into your macro that offers a bit more control of the process.

They're particularly useful when connected to the AnchorQ_out.png anchor of a Macro Input tool.

 

select with config.PNG

 

You can then update a Select tool with the selected field to choose which field is being passed along.

 

Advantages:

1.  Allows you to specify which fields to show to the user from a list of field types. (In this example, I am only allowing spatial objects.)

2.  You can have a default selection populate the interface. (Here we will have any field starting with "SpatialObj" get selected automatically in the configuration of the macro.)

3.  If you want something to be optional, you can use the [None] option.

 

"The Select Tool Trick"

 

If you make use of the Drop Down tool to bring in your data you'll need to update a Select tool. Here's a little trick that will make converting your workflows a lot easier.

 

select config.PNG

 

First you'll want to uncheck *Unknown in the Select tool, since this will bring in every field not explicitly unchecked here. Then, have only the field you're selecting for checked, and navigate over to your Action tool and point it at the selected field.

 

 

action.PNG

 

Instead of having this repeated for every tool using this field, just have the field renamed in the Select tool, and refer to it by that name in all your downstream fields.

 

This turned out to be just what I needed for the Make Hex Grid macro, where I have a ton of stuff happening downstream and I only wanted one field to get through my Select tool.

 

make hex grid browse.PNG

 

Check out the example for a simplified version of this.

Attachments