We are celebrating the 10-year anniversary of the Alteryx Community! Learn more and join in on the fun here.
Start Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

in a macro i have created a new field, how can i refer back to it inside the macro still

LFerg
6 - Meteoroid

The overall case is that I am trying to make a macro that will allow for proper punctuation cleanse and titlecase for fields with names so it respects hyphenated names and double-barrel names.

 

LFerg_0-1663861616365.png

 

In the third Multi-Field Formula i am using the option to "Copy Output Fields and Add" New_ as prefix. 

In the fourth one I would then like to refer to that new field so that in the following code, in the two places where it refers to [Last]  it would instead refer to the newly created variable.

 

IF REGEX_Match([_CurrentField_], "([\w]')([a-zA-Z]+)") 
then 
REGEX_Replace([_CurrentField_], "([\w]')([a-zA-Z]+)","$1"+[Last]+"") 
ELSEIF REGEX_Match([_CurrentField_], "(\w*\-)([a-zA-Z]+)") 
then REGEX_Replace([_CurrentField_], "(\w*\-)([a-zA-Z]+)","$1"+[Last]+"") 
ELSE [_CurrentField_] ENDIF

 

Is there any expression like New__CurrentField__ or similar that I can use? Do I need to change something with the flow?

 

I am still working on perfecting the expression, but I am trying to work out how to get my current formula into a macro. 

In the test file I have attached is the current formula process flow and a flow with the macro. I have also attached the macro (which i am aware doesn't work on anything but the test_field. but that's for another post)

3 REPLIES 3
MattBSlalom
11 - Bolide

The Dynamic Select tool is what you need to get the result you've described.  

MattBSlalom_0-1664215099398.png


In the example above, we first add a Record Id so that we can split the logic and have a way to combine it again at the end.  Next, we add a pair of the Dynamic Select tools with essentially opposite criteria to make sure every field is pulled into one or the other (with the new Record Id going through both).

 

1st Dynamic Select:

 

MattBSlalom_1-1664215309795.png

 

 

2nd Dynamic Select:

 

MattBSlalom_3-1664215371940.png

 

The 4th Multi-Field Formula tool then is applied only to those fields that had the "New_" prefixed field names.  Finally, a Join tool is used to combine the "New_" fields back with the original fields using the Record Id field as the join field (be sure to uncheck the Record Id fields from the field list in the Join tool to keep them from flowing to the Output tool).

LFerg
6 - Meteoroid

Thank you. I see what that does and have certainly learned something.
I'm still not sure how to change the code though to reference the New_ variable though. 

MattBSlalom
11 - Bolide

The Dynamic Select tool in the top flow is removing all fields that aren't the "New_" fields (and the Record Id field).  Therefore, there's no need to specifically reference the "New_" fields separate from other fields (since there are no others) in the 4th Multi-Field Formula tool (so just select all Text fields).

Labels
Top Solution Authors