Skip to main content
manjit.1486
February 14, 2024
Question

Sort foreach Data

  • February 14, 2024
  • 2 replies
  • 0 views

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(
        "",
        "",
        union(
          { fv!item.empcode },
          { fv!item.empcode }
        ),
        "",
        "",
        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]
          )
        ),
        "",
        "",
        union(
          { fv!item.empname },
          { fv!item.empname }
        ),
        "",
  
        "",
        fv!item.type,
        "",
 
        "",
        fixed(
          abs(index(fv!item,"amount",{})),
          2
        ),
        "",
        ""
      )
    ),
    char(10)
  )

2 replies

mathieud0001
February 15, 2024

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
  )
)

manjit.1486
February 16, 2024

Thank you so much.