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!

Alteryx Designer Desktop Knowledge Base

Definitive answers from Designer Desktop experts.

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

AlexKo
Alteryx Alumni (Retired)
Created

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 allowthe user to select which field to use in a very complex process. Take the Make Grid tool for example. It asks the user to specifya 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, andwhen 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 theTemplate 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 ifyou 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 thestuff coming out of the macro.

Drop Down

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

They're particularly usefulwhen connected to theAnchorQ_out.pnganchor of a Macro Input tool.

select with config.PNG

You can then update a Selecttool 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*Unknownin 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 andpoint 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
Comments
gwiz
8 - Asteroid

Say I have a file with some header rows first, I wouldn't be able to use the drop down to update the select because at the onset it would just show my fields as F1, F2, F3, etc. Can i pass a drop down later after it gets rid of the header rows, does a dyanmic rename to get the field names and then use the drop down to show actual field names like Account, Order, Product, etc?