Lompat ke konten

Pelajaran 18 ยท Macros and Apps

Building Standard Macros

Turn repeated steps into an Alteryx standard macro with Macro Input, Macro Output and interface tools, then test, document and version it.

If you copy the same group of tools between workflows, every fix must be repeated many times. A macro packages those steps into a single reusable tool. It is similar to a function in programming: inputs go in, outputs come out, and settings change the behavior.

A standard macro runs once for the data you give it. This lesson shows how to build one.

The parts of a macro

Part Tool Purpose
Data in Macro Input Defines an input anchor and sample data
Data out Macro Output Defines an output anchor
Settings Interface tools Let the user choose values
Wiring settings to tools Action Updates a tool's configuration with a value

A macro is saved as a .yxmc file. Interface tools, in the Interface category, include Text Box, Drop Down, Check Box, Numeric Up Down, List Box, File Browse and others.

flowchart LR
  I["Macro Input"] --> C["Cleaning tools"]
  C --> O["Macro Output"]
  T["Text Box"] --> A["Action"]
  A -.updates settings.-> C

A setting flows from an interface tool through Action into a tool's configuration.

Build a key-standardizing macro

  1. Select the tools that you reuse, such as a Formula that trims and uppercases a key.
  2. Replace the input with a Macro Input tool and give it sample data that covers the awkward cases.
  3. End with a Macro Output tool.
  4. Add interface tools for anything that should vary, such as which field to clean.
  5. Connect the interface tool to an Action tool, and connect that to the tool you want to change. Pick which setting the action updates.
  6. Set the workflow's type to Macro in the workflow configuration, then save as .yxmc.

Some conversion options can generate parts of this for you, but you should understand each piece.

Choose the macro's template input data carefully. Macro Input sample data lets you run and test the macro on its own, before anyone else uses it.

The function analogy

Python Stand-in: a macro behaves like a function with settings

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice that the function does not change the original list. A good macro also has clear inputs and outputs without surprising side effects, such as writing files you did not ask for.

Handling different schemas

The incoming data may not look like your sample. Consider these:

  • The user picks a field with a Drop Down that is filled with the incoming field names.
  • The field has an unexpected type. Check it, or convert it inside the macro.
  • Extra columns arrive. Make sure they pass through when that is what users expect.
  • A required column is missing. Report a clear error, for example with the Message tool, instead of producing odd output.
Python Stand-in: validate the input before processing

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Using your macro

You can insert a macro into another workflow from its file, or add its folder to your list of macro search paths so that it appears in the tool palette. Depending on your license and version, macros can also be shared through the platform's library. When you move a workflow, make sure the macro files travel with it, or live in a shared place that everyone can reach.

Documenting and versioning

A macro that only you understand is a risk. Write down:

  • What it does and what it does not do.
  • Required input fields and types.
  • What each setting means, including defaults.
  • Output fields.
  • Owner and version.

Keep the macro files in version control if your team uses it. Changing a macro changes every workflow that calls it, so treat it like a shared library: test with the old sample data and new edge cases before you publish a change.

Testing a macro

Make a small test workflow with Text Input data, run the macro and compare the output with the expected table. Include:

  • An empty input.
  • Null values and blank strings.
  • Unusual characters.
  • A very long value.

The Test tool in the Developer category can help you check conditions such as record counts. Testing and debugging covers it more.

When a macro is not the answer

A macro adds a layer that readers must open to understand. It pays off when the same logic is used in several places, or when you want others to use it without knowing the details. For steps that appear only once, a Tool Container with a good label is usually clearer.

Also keep the contract small. A macro with fifteen settings is hard to test, because the number of combinations grows quickly. If users need very different behavior, two focused macros are often better than one with many switches. Name each macro after what it does, such as standardize_customer_key, not after the project where you first needed it.

Practice task

Write the contract for a macro that flags invalid email values: its input fields, its settings, its output fields and what it does with nulls and empty input. Then create five test rows and the expected output.

If you have Designer, build the macro, call it from a test workflow and compare the results. Rename the input column and check that the user gets an understandable message.

Common mistakes

Do not hard-code a local file path inside a macro. It will fail on another computer, and users may not notice which file it reads.

  • Skipping validation of required columns.
  • Updating the wrong setting with the Action tool, so the value never takes effect.
  • Making one giant macro that does many unrelated things.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which tools define the data anchors of a macro?

    They create the macro's input and output anchors.
  2. 2. What does the Action tool do?

    It connects a user's choice to the settings that should change.
  3. 3. What is the file extension of a macro?

    Macros are saved as yxmc files.
  4. 4. Why test a macro with empty input?

    Real data is sometimes empty, and the macro should handle it clearly.

Summary

  • A standard macro is a reusable tool saved as a .yxmc file.
  • Macro Input and Output set anchors; interface tools plus Action set options.
  • Validate inputs and handle schema changes with clear messages.
  • Document, version and test macros like shared code.

Next: Batch and Iterative Macros

Progres Anda disimpan di browser ini. Tidak perlu akun.