Sort foreach Data

Certified Senior Developer

Can anyone please hep me in this?

I want to sort below mentioned data. I was trying to sort data using queryentity and it worked. But I have to use rule input ri!employee(Type: Data Type). Please assist. 

Need to sort data by these fields:

sort: {
a!sortInfo(field: "empcode", ascending: true()),
a!sortInfo(field: "type", ascending: true()),
a!sortInfo(field: "amount", ascending: true()),
}

 joinarray(
    a!forEach(
      items: ri!employee,
      expression: concat(
        "<tr>",
        "<td>",
        union(
          { fv!item.empcode },
          { fv!item.empcode }
        ),
        "</td>",
        "<td>",
        if(
          rule!GLB_isBlank(fv!item.barcode),
          {},
          a!localVariables(
            local!code: union(
              { fv!item.barcode },
              { fv!item.barcode }
            ),
            local!newcode: split(local!code, "_"),
            local!newcode[2]
          )
        ),
        "</td>",
        "<td>",
        union(
          { fv!item.empname },
          { fv!item.empname }
        ),
        "</td>",
  
        "<td>",
        fv!item.type,
        "</td>",
 
        "<td>",
        fixed(
          abs(index(fv!item,"amount",{})),
          2
        ),
        "</td>",
        "</tr>"
      )
    ),
    char(10)
  )

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    All you need to do is wrap the list of employees with todatasubset to do the sort without a query.

    a!localVariables(
      local!dataSubset: todatasubset(
        ri!employees,
        a!pagingInfo(
          startIndex: 1,
          batchSize: -1,
          sort: {
            a!sortInfo(field: "empCode", ascending: true, ),
            a!sortInfo(field: "type", ascending: true, ),
            a!sortInfo(field: "amount", ascending: true, )
          }
        )
      ),
      a!forEach(
        items: local!dataSubset.data,
        expression: fv!item.empCode
      )
    )

Reply
  • 0
    Certified Lead Developer

    All you need to do is wrap the list of employees with todatasubset to do the sort without a query.

    a!localVariables(
      local!dataSubset: todatasubset(
        ri!employees,
        a!pagingInfo(
          startIndex: 1,
          batchSize: -1,
          sort: {
            a!sortInfo(field: "empCode", ascending: true, ),
            a!sortInfo(field: "type", ascending: true, ),
            a!sortInfo(field: "amount", ascending: true, )
          }
        )
      ),
      a!forEach(
        items: local!dataSubset.data,
        expression: fv!item.empCode
      )
    )

Children