Skip to main content
Question

GROUPBY Function now available?

  • October 11, 2022
  • 0 replies
  • 36 views

I visited the QuickBase article (About Jinja) and read that "Pipelines is currently supporting Jinja 2.11.2, for various formatting within pipeline steps". That webpage also also provides a link for the syntax and semantics of jinja 2.11.2. 

My question is, according to the syntax of jinja 2.11.2, one should be able to use the function GROUPBY(value, attribute), however, I can't seem to get it to work. 

Is anyone able to confirm or deny/ provide an example within Pipelines?



------------------------------
Shane Miller
------------------------------
This topic has been closed for replies.

Forum|alt.badge.img+6
  • Quickbase Staff
  • October 12, 2022
Hey Shane, here's a quick example using the Text step:
{% set users = [
  {
    "id": 1,
   "name": "bob",
  "city": "Boston"
  },
  {
    "id": 2,
   "name": "jane",
  "city": "Boston"
  },
  {
    "id": 3,
   "name": "george",
  "city": "Baton Rouge"
  }
] %}
{{ users | groupby("city") }}​


The results in the activity log:

text:"[(u'Baton Rouge', [{u'city': u'Baton Rouge', u'id': 3, u'name': u'george'}]), (u'Boston', [{u'city': u'Boston', u'id': 1, u'name': u'bob'}, {u'city': u'Boston', u'id': 2, u'name': u'jane'}])]"


As you can see, the list is now grouped by the city, with each city results in a nested list.

The example on the Jinja website works to parse this sample data. Remove the last line from the Jinja above and add this to the end:

<ul>{% for city, items in users|groupby("city") -%}
  <li>{{ city }}
    <ul>{% for user in items -%}
      <li>{{ user.name }}
    {% endfor -%}</ul>
  </li>
{% endfor -%}</ul>


The outer loop references the first value as 'city' and the second value as 'items' which is the list for that city. The inner loop iterates the items for that city.

Hope that helps!



------------------------------
Doug Henning
------------------------------