test1: {{property.suite_types|map(‘baths_low’)}}
test2: {{property.suite_types|map(‘baths_low’)|sort(false,false,‘’)}}
I have some code like above, suite_types is an array of objects where each object has a property called “baths_low”. “baths_low” is some float number like 0.5, 1, 1.5 etc.
When I test the code, as you can see below, the sort returns nothing if the value is in float and has different.
sort works fine on whole number through…
I believe the data in the array has to be the same type. You can try putting a |map(“float”) to convert all the numbers into a float before sorting.
{{property.suite_types|map('baths_low')|map('float')|sort(false,false,'')}}
map(‘float’) is invalid in Hubl.
Not sure why you think so.
Documentation for map states that you map a filter.
- Alternatively, you can let it invoke a filter by passing the name of the filter and the arguments afterwards.
And it clearly works although you have to be careful on the order of the filters.
they are all type ‘number’ in my hubdb column, unless hubspot treat 1 as int, 0.5 as float internally.
even then the sort filter should handle number type automatically
Yes, hubspot treats the whole numbers and decimals numbers differently. If you build an object array in hubspot similar to your structure, you can see that apply a sort doesn’t work.
If you apply a map|(‘float’), it should resolve it
Test 01 should match similarly to what you should in your original post and will fail to output sometihng.
Test 02 is appyling a map float.
Try sorting the original array directly before mapping
same issue as it is the sort function error out when comparing 1 with 0.5
Hi @iqoOopi
This happens when a list contains a mix of whole numbers and decimals. It can cause errors during sorting or calculations. That’s because HubSpot’s Java-based backend treats integers and decimals differently and won’t automatically convert between them.
Easy fix: Use the float filter to convert all values to decimals first.
Easy fix: Use the float filter to convert all values to decimals first:
{% set suite_types = [
{ baths_low: 12 },
{ baths_low: 0.1 },
{ baths_low: 10 },
{ baths_low: 0.5 }
] %}
{{suite_types|map('baths_low')|map('float')|sort(false,false,'')}}
This will return sorted array [0.1, 0.5, 10.0, 12.0]
I hope this will help you out. Please mark it as Solution Accepted and upvote to help another Community member.
Thanks!