Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

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

Unknown Number of Inputs in a Macro

Sylvain
5 - Atom

Hi all,

 

I am working on a project to integrate MATLAB Produciton Server (MPS) with Alteryx.

The first step is to write some Macros to convert Alteryx datatypes to their appropriate JSON representation.

To illustrate this, I attached an example Macro that would turn and Alteryx array (a signal's field) into its MPS JSON representation.

 

What I would like to do is be able to make a Macro that could take an unknown number of input fields so I could write a "matrix" representation, instead of an "array" one (which would be NumberOfObservations x NumOfRows).

 

To do that, I would need to:

  1. Design the Macro Input so the user could check any of the incoming fields. I managed to get reasonably close by using a DropDown, but then, in the MacroInput, I still had to specify an arbitrary number of fields.
  2. Be able to work with an unknown number of fields. I could easily write a Macro for matrix with 2 columns, and one with 3 columns, but how do I write a macro that deals with any arbitrary number of columns?

To be honest, I am not even sure this can be done with Alteryx, but I figured I would ask before drawing any conclusions.

 

Thanks in advance for any help,

 

Sylvain

4 REPLIES 4
KaneG
Alteryx Alumni (Retired)

Hi @Sylvain,

 

Are you referring to the 'field map' as the dropdown?

 

What do you want the user to be able to select? Which field is the array field, or which fields should come through and be included in the JSON?

 

I'm assuming though that you are after the situation where there could be any number of fields that will need to be included in the JSON, but not necessarily all the fields. In this case, I would add a transpose either after your formula tool that creates JSON_NAME or before the recordID depending on whether you need different JSON_Names and different ID's and have those Data Fields updated by a List Box. The List Box will allow the user to select all the columns that they would like added to the data.

 

The catch, AND THIS IS IMPORTANT, if you connect to the green connector on the Macro Input, then you will only populate the Interface tool with the sample metadata in the Macro Input, not with the dynamic metadata that is input. You will need to connect to the 'Q' icon on the Macro Input.

 

So, there are a couple of things to possibly change depending on exactly what you're after. I've attached an example of your macro with the fieldlist and another RecordID (multi-row for numbering the transposed columns), so you can pick what is needed. Normally, where I have edited the formula to include the new ArrayIndex in the Json, you would possibly just include the fieldName.

 

Kane

Sylvain
5 - Atom

Hi Kane,

First of all, thank you very much from taking the time to look at this.

You perfectly understood what I was trying to do, and your answer almost got me where I need to be.

Building up from what you explained (I did not understood how to use the transpose, proved pretty powerful), I got the attached macro, with the little demo workflow.

As you can see, there are two issues:

  1. In the workflow, I still need to map 2 of the fields in the drop down of the macro interface, which feels a little odd, as I then check/uncheck what I want. Can I remove that mapping? I couldn't figure out how.
  2. The fields that I end up mapping to those drop down never come back out of the macro. It feels like they get renamed by the Macro Input, and the "Field Map" fails to toggle them.
KaneG
Alteryx Alumni (Retired)

So close... On the Macro Input, de-select 'Show Field Map'.

 

Also, possibly need to preserve the fields that aren't selected. (Not sure if you need to do this, depends on what that info holds). One way to do this is a Select tool after the transpose (on a different path), with Name/Value de-selected but Unknown checked. This will keep everything except the fields that were transposed. You can then join/append that back on somewhere, but be careful if it has more than one row, as you'll duplicate your JSON.

 

Preserve_fields.png

Sylvain
5 - Atom

Spot on!

Thank you very much for your help Kane!

Labels