Forum Discussion

MalcolmMcDonald's avatar
MalcolmMcDonald
Qrew Cadet
2 years ago

Grouping and Listing fieldnames and values in Pipelines

I'm importing a flat file of workorders into a staging table, then looking to load it into the production tables. 

The file has about 24 columns of parts that could be installed, with a count.  Looks a bit like the below:

DOORBELL CAMERA INDOOR CAMERA OUTDOOR CAMERA TAKEOVER MODULE DOOR/WINDOW SENSOR
1       2
1   1   2

I'm not using this data for inventory .. it's purely informational.

Using pipelines - is there an easy way put all those columns into a single multi-line text block, separated into a list - skipping over the blank ones?  EG -- that first record would like the below or similar:

Doorbell Camera: 1 | Door / Window Sensor: 2

Thanks!



------------------------------
Malcolm McDonald
------------------------------

2 Replies

  • DougHenning1's avatar
    DougHenning1
    Community Manager

    Hi Malcolm, this block will output close to what you want.  You'll need to update the list of fields on line 2, and replace 'c' on lines 3 and 5 with the appropriate step letter in your pipeline:

    {# Define the list of fields to use -#}
    {% set fields = ['doorbell_camera', 'indoor_camera', 'outdoor_camera', 'takeout_camera', 'door_window_sensor'] -%}
    {% for field in fields if c[field]|int > 0  -%}
    {# Format/capitalize the field name -#}
    {{field.split('_') | map('capitalize')|join(' ') }}: {{c[field]}}{{ ' | ' if not loop.last }}
    {%- endfor -%}

    Sample output:

    Doorbell Camera: 1 | Takeout Camera: 3 | Door Window Sensor: 2

    The field names don't have the exact formatting (e.g. no slashes) since that info isn't available on the jinja field name. 

    Hope that helps!



    ------------------------------
    Doug Henning
    ------------------------------
    • MalcolmMcDonald's avatar
      MalcolmMcDonald
      Qrew Cadet

      Actual genius .. thank you Mr. Henning!

      And for future searchers on this topic .. I had quite a number of "illegal" characters in the field name, but the pipeline field picker showed me what to do .. so for eg - Doorlock(Brass-15) shows as {{a.doorlock_brass_15}} .. ie the jinja needs the open parenthesis as an underscore, but drops the close parenthesis entirely.



      ------------------------------
      Malcolm McDonald
      ------------------------------