HubDB - Multiselect order

SOLVE
Highlighted
Regular Contributor

Hello
I have a multiselect column.
Is there a way to print the values in the order they were added into a particular row?
Right now values get ordered by id.

0 Upvotes
1 Accepted solution

Accepted Solutions
Highlighted
Solution
HubSpot Alumni

Hi @rainism,

 

It looks like by default the items do in fact get printed according to their "order". Their "order" values are determined by the order in which the options are listed in the edit modal of the multi-select column options. So you could re-arrange the options themselves, but that's not specific to any specific row where the options are used. In every single row, wherever an option is used, it will always have the same value for its order.

 

There is a |sort() filter, which you can find documentation for here: https://designers.hubspot.com/docs/hubl/hubl-supported-filters#sort. You could for example re-arrange the multi-select options by their name (which is alphabetical). But there's nothing like a timestamp stored in these option dictionaries to indicate when they were added to a row. So using the |sort() filter might look something like this (in case you want to play around with it):

 

{% for item in row.multiSelect|sort(false, false, 'name') %}
  <p>item.name: {{ item.name }}</p>
{% endfor %}

I think there's a use for being able to sort by date added though, so I'd suggest creating an idea for it here: https://community.hubspot.com/t5/custom/page/page-id/ideaslandingpage. And I'm happy to vote on your idea as well, so make sure to link back to it here.

 

Let me know if you have any other questions here.

 

Leland Scanlan

HubSpot Developer Support

View solution in original post

1 Reply 1
Highlighted
Solution
HubSpot Alumni

Hi @rainism,

 

It looks like by default the items do in fact get printed according to their "order". Their "order" values are determined by the order in which the options are listed in the edit modal of the multi-select column options. So you could re-arrange the options themselves, but that's not specific to any specific row where the options are used. In every single row, wherever an option is used, it will always have the same value for its order.

 

There is a |sort() filter, which you can find documentation for here: https://designers.hubspot.com/docs/hubl/hubl-supported-filters#sort. You could for example re-arrange the multi-select options by their name (which is alphabetical). But there's nothing like a timestamp stored in these option dictionaries to indicate when they were added to a row. So using the |sort() filter might look something like this (in case you want to play around with it):

 

{% for item in row.multiSelect|sort(false, false, 'name') %}
  <p>item.name: {{ item.name }}</p>
{% endfor %}

I think there's a use for being able to sort by date added though, so I'd suggest creating an idea for it here: https://community.hubspot.com/t5/custom/page/page-id/ideaslandingpage. And I'm happy to vote on your idea as well, so make sure to link back to it here.

 

Let me know if you have any other questions here.

 

Leland Scanlan

HubSpot Developer Support

View solution in original post