Wednesday 9 July 2014

Changing sort order of index fields

Situation
Information in Infor LN is mostly sorted using one if the indices. The default sort order is always ascending. Suppose, you write history each time a user changes an item. The item history is stored in a separate table tcibd321 and the first index consists of the field “item” and “changed on date”. If you show the history in a list window, the data is generally sorted ascending by “item” and “changed on date”. However, the requirement is to show the latest change on top. So, we need to influence the order of one of the index fields.

Solution
A new tools function is available to change the order of the index fields.
The syntax is as follows:
function long query.define.sort.order(long table.index, const string field.var, direction.var [, const string ..., ...])

Use this function to set the sort order of a field of a table index. The function overrides the sort order of parts in the table index for the current session only.
The function does not override the field sort order of an active filter. You can use this function in the section before.program. In other sections you need to activate this feature by using the function rebuild.query(). One or more index fields with the required sort order can be set.


Example
How to get the history information from the example above in the required order? Use the new function in the before.program.
before.program:
long ret
ret = query.define.sort.order(1, "tcibd321.date", "desc" )
if ret < 0 then
|* an error message can be shown ...
Endif

TIV
This function is available from TIV level 1900 and higher.

2 comments:

  1. Hi I have used this function [query.define.sort.order], but its giving me error of "unresolved reference".

    Do I need to Include something to use this? Pl guide..
    Thanks in Advance!!

    ReplyDelete
  2. It is available from TIV number 1900 onwards.

    ReplyDelete