does anyone know if there's a freemarker way to do...
# advancedpdf
a
does anyone know if there's a freemarker way to double-sort lines? e.g. i want to sort by date and then by item ID, so that it looks something like:
Copy code
1/1/2020 - item A
1/1/2020 - item B
1/2/2020 - item A
1/2/2020 - item A
1/2/2020 - item B
s
My usual approach to sort by multiple fields is to create a custom formula text field which concatenates two or more fields together, and then to use that formula field for sorting. Something like this:
TO_CHAR({custcol_date}, 'YYYY-MM-DD') || {item}
a
that's actually what suiteanswers recommended as well, although unfortunately it doesn't seem to be working so well for my use case - in order for the formula field to populate it has to have store value = false; but in my particular scenario (sorting time entry lines on the invoice) when the custom field on time entry is set to store value = false, it doesn't get carried over to the invoice record (which is where the sorting/printing takes place). Your solution is probably the cleanest one though, my situation is just overly complicated haha. I'm now thinking I can either have a script/workflow set the formula on the stored value field, or within my PDF, loop through once and set the concatenated value as a custom variable in a new hash, and then sort that new hash and loop through when actually printing.
m
You should be able to chain the `?sort_by`'s, e.g.
record.item?sort_by('field2')?sort_by('field1')
.