06-22-2017 04:22 PM - edited 07-09-2021 08:59 AM
I was asked this question in the Solutions Center at Inspire this year, and as it turns out, it is surprisingly easy. Shout out to Chad Martin for providing the answer.
When you're setting up your Macro Input tool, make sure to use the Field Map option. After that, it's as easy as adding '(Optional)' next to the field names you want the user to not be required to map:
The end result is an interface in the final macro that looks like the below:
A very simple sample (built in 11.0) is attached for reference.
Holy cow, this is awesome! Thanks for passing it along.
So very happy to know this!
:-) that's very useful, thank you - and something that no-one would know if you hadn't seen the internals
So I played around with at a bit - am I right that Alteryx is just doing a text-match for the exact string '(Optional)' to determine if a parameter is optional or not?
Do you have a sense of when the parameters for macros are due for an overhaul to allow for strict typing? When this hits the priority queue, it would worth managing the optionality of the input params in the same sprint.
Thanks for passing this on.
I've been trying to hack a solution to this all afternoon +1 * 1000000
Can someone confirm this is still working? It's not working for me in 2019.3 or 2020.3 and for @pjungels https://community.alteryx.com/t5/Alteryx-Designer-Discussions/Using-Optional-Macro-Inputs/m-p/645866
@AndrewL @LordNeilLord @SeanAdams @Hollingsworth @patrick_digan
@joshuaburkhow @pjungels It truly is optional in the macro input. Here would be the error if we didn't put (Optional) at the end of the field name:
With that said, not having the field may cause problems downstream. In your example, the formula tool is throwing an error because it was expecting a field called Test (Optional) which doesn't exist. The easiest work around is to use the ensure fields macro which is part of the crew macros. Alternatively, you can see in the heat map tool how they handled the optional field:
Thank you @patrick_digan! That is exactly what I was looking for. The Ensure Fields macro works perfectly for "cleansing" those optional fields for use within the macro. It's also nice to know there are workarounds to do this manually if needed.
The (Optional) argument isn't working for me with 2020.3. FieldName[space](Optional)
@john_watkins - it's working for me in 2020.3. Can you describe what you are seeing (error message, etc.)?
It runs my macro and throws an error stating that "The field [XYZ] (Optional) is not contained within the record. This is possibly because I'm using it in the macro, but I assume if there is no value passed, that the tool would just set it to Null or something. This may be an incorrect assumption.
See the response from @patrick_digan above. In short, the Ensure Fields tool in the CReW macros helps to cleanse/normalize optional fields, adding them as NULL if they are not present.
I did name the field Optional and then did use the CReW macros to clean it up. That was my final resolution to that issue.