This site uses different types of cookies, including analytics and functional cookies (its own and from other sites). To change your cookie settings or find out more, click here. If you continue browsing our website, you accept these cookies.
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.
Suppose you have a dataset that will pass through a macro if a condition is true, and an entirely different macro if a condition is false. In the event the condition is true for all records, no records will be sent to the false-side macro. The false-side macro is expecting data and throws an error whenever it doesn't find any. Similarly, in a case where the condition is false for all records, no records will sent to the true-side macro and errors. You need a process that will bypass the macros whenever data is unavailable. Let’s see how you can do that.
First, create data senarious where all conditions can be tested. In the first situation, I assigned a field, Sum_Test, with a value of 1 to half of the records and a value 0 to the other half. A second situation assigns a value of 1 to all records. A third situation assigns a value of 0 to all records. Setting up these situations will allow me to test all possibilities.
The next step is to filter by condition. Depending which data senario from above you use, data may not exist if the condition is true or false. No data means your workflow will fail. We need a work-around so that doesn't happen.
What happens after the data goes down the true side or the false side is essentially the same in terms of process. The batch macro below is found downstream from the true side as well as the false side. Functionally, they work the same. The batch macro determines if data is available. If there is, data is detoured to the formula tool. If not, the detour will bypass the formula tool entirely and keep the workflow from throwing a error.
NOTE: the formula tool in the illustration below is a representation of any process that requires data if an error is to be avoided. This could anything, usually another macro. For the purpose of this illustration, I'm simply showing a single tool.
What follows are instructions for how each tool in the batch macro/detour combination are configured.
First, enter ‘Sum_Test’ as the label for the Control Parameter.
Then write an expression in the Condition tool that checks if ‘Sum_Test’ is null.
If ‘Sum_Test’ is null (True), then direct the detour tool to go to the right in the ‘T’ side action box.
Similarly, if ‘Sum_Test’ is not null (False), then direct the detour tool to go to the left in the ‘F’ side action box.
Connect both action boxes to a Detour tool. The Detour tool has no configuration.
Every Detour must be stopped by a Detour End tool.
Build a similar batch macro for the false side of Filter tool.
Union the results from the true and false sides.
I put a Frequency Table tool after the Union to verify the results.
The entire process looks like this:
Disconnect the input to the filter tool and connect a new test condition to test all the various conditions.