0

How can I sort by "date2"? That is, on the additional field "date"?

<#assign
    orstf = objectUtil('com.liferay.portal.kernel.dao.orm.RestrictionsFactoryUtil')
    qry = assetEntryLocalService.dynamicQuery()
/>
<#if startDate??>
    <#assign
        V = qry.add(orstf.ge('publishDate', startDate?date("dd.MM.yyyy") ))
    />
</#if>
<#if endDate??>
    <#assign
        V = qry.add(orstf.le('publishDate', endDate?date("dd.MM.yyyy")))
    />
</#if>
<#assign
    entriesRaw = assetEntryLocalService.dynamicQuery(qry)
    entries = []
/>

<#-- ?sort_by(['name', 'last']) -->

<#list entriesRaw as entry>
    <#assign 
        eCatIds = entry.getCategoryIds() 
        renderer = entry.getAssetRenderer()
        journalArticle = renderer.getArticle()
        date2 = journalArticle.getExpandoBridge().getAttribute("date")
        bContains = 0
    />
    <#list eCatIds as eCatId>
        <#if (catIds?seq_contains(eCatId)) &&
            (date2?date >= startDate?date("dd.MM.yyyy")) &&
            (date2?date <= endDate?date("dd.MM.yyyy")) >
                <#assign bContains = 1 />
        </#if>
    </#list>
    <#if bContains == 1>
        <#--
        <#assign entry.set />
        -->
        <#assign entries = entries + [entry] />
    </#if>

</#list>

I thought it might work out, write it down to some field of the asset. And on this sort. But this is also not good, every time the database is tugged

1 Answers1

0

Especially in the Netsuite fork of FreeMarker, you won't do this (assuming you can't add helpers written in Java), because that fork doesn't even support ?map, which can be used for sorting by a calculated filed, like date2 is here. (Although even with that, ?sort_by as of 2.3.31 only supports sorting by a single field, so you had to do some hack where you concatenate the two fields into one. Even if ?sort_by will be improved in FreeMarker later, that certainly won't make its way into the Netsuite fork, sadly.)

Anyway, the assumption in FreeMarker is that sorting and other such query operations (like joins, etc.) is the duty of the data access layer, not of the template. In this vein, it's certainly assetEntryLocalService.dynamicQuery that should support whatever sorting the reports need.

ddekany
  • 29,656
  • 4
  • 57
  • 64