on 02-16-2016 02:48 PM - edited on 07-16-2023 01:43 AM by ahsanaali
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.
Thank you, I was struggling with this issue just the other day.
"This article is part of the Client Services Macro Development Series" - does this series have a home page? Or a way to subscribe to it?
Hi @alex,
Thanks for the request! So far we don't have a home page for this series but you can subscribe to new articles by using Community's Search subscription feature.
To do this, click your name in the top-right and then "My Subscriptions":
Then navigate to "Subscriptions & Notifications" and then to "Search Subscriptions":
Then just type in our tag, CS Macro Dev to get a notification when new articles are posted!
Cheers,
Alex
Thank you for your suggestions alex, you have helped me a lot in my own macro development!
You can now subscribe to the label CS Macro Dev to see all the articles in this series.
Very cool Wayne!
FYI - it would have saved me a few minutes of wrapping my head around your approach if the YXZP contained actual YXMC batch macros embedded into the YXMD (rather than the dummied up tools right in the workflow itself). Met the need perfectly though so thanks a bunch!
Hi Wayne,
I seem to be having some trouble with this. I downloaded your flow and ran it, but it does not seem that the detour tool is being affected by the macro. Regardless of whether Sum_Test is null or not, the flow always runs through the left side of the detour. Additionally, if I check the "Detour to the Right" box in the detour configuration window, then the data always flows to the right (again, regardless of whether or not Sum_Test is null). So it seems that data is simply flowing in the direction of the detour configuration, not based on the condition.
Would you mind assisting?
Interesting - I just tested the same and it does not work.
I reduced the sampling to 5 records with Sum_Test values set to 0, 1, Null, True and False, and then passed all 5 records to the [Sum_Test] > 0 Control Parameter. None of the Sum_Test values changed the outcome of the Condition Tool to TRUE. I also changed the data type to Boolean, Int16, and String, with no change in outcome. Using the Control Parameter, Condition, and Action tools in various combinations did not result in a single outcome where the Control changed the Detour to Right flag from false to true.
It appears to me that the Detour tool is faulty in that the only way to redirect the output from right to left is manually via the checkbox.