Description

Examples of sorting Order Lines.

 

Flow of events



There are two events for sorting order lines:

1 . OnAfterSetCurrentKey-events

    • Set Sorting Direction
    • Set a new key using any of the fields in the Element table.
    • This will affect the 'Sorting' value in the Xml indirectly by affecting the looping of the record.
    • Can only be used if the value to sort exists as a field in the Element table.

2 . OnAfterSetFrom-events

    • Set Sorting1, [Sorting2, ...] values directly (internal fields used only for sorting).
    • 'Sorting' in the Xml is generated during a looping of the record
    • If no other key is set, default sort order is "Sorting1, Sorting2, Sorting3, Sorting4, Sorting5".
    • Can be used to sort on any value, including custom values that do not exist as fields in the Element table.


Sorting on Existing fields

Use OnAfterSetCurrentKey-events.


  • Change sorting key
    • Use .SetCurrentKey(field, [field2, ...])-function with any of the existing fields from the Line table (Record parameter on this event).


  • Change sorting direction
    • Use .Ascending(true/false)-function. 


  • Use these events:


Sorting on Custom fields

Use.OnAfterSetFrom-events.


  • Change sorting key 
    • Use Set_Sorting1()-function.



  • Change sorting direction
    • This is done in two steps:
    1. Use OnAfterSetFrom[ and the Set_Sorting1()-function.
    2. Use OnAfterSetCurrentKey and the .Ascending()-function.


Helper Functions

The event parameter "_BaseOrderLineElementView" includes five sorting functions you can use to sort on up to four new custom fields .


Example: Existing fields

  • Change key to existing field "Item no."
  • Change sorting direction to "Descending"

For this task you can use an OnAfterSetCurrentKey event.


[EventSubscriber(ObjectType::CodeunitCodeunit::"MOB WMS Receive", 'OnGetReceiveOrderLines_OnAfterSetCurrentKey''', true, true)]
procedure OnGetReceiveOrderLines_OnAfterSetCurrentKey(var _BaseOrderLineElementView: Record "MOB Ns BaseDataModel Element")
begin
     _BaseOrderLineElementView.SetCurrentKey(ItemNumber);
     _BaseOrderLineElementView.Ascending(false);
end;
 



Example: Custom fields

  • Sort lines by you own custom field

For this task you must use the OnAfterSetFrom event.


[EventSubscriber(ObjectType::CodeunitCodeunit::"MOB WMS Receive", 'OnGetReceiveOrderLines_OnAfterSetFromAnyLine''', true, true)]
procedure OnGetReceiveOrderLines_OnAfterSetFromAnyLine(_RecRef: RecordRefvar _BaseOrderLineElement: Record "MOB Ns BaseDataModel Element")
var
     Item: Record Item;
begin
     with _BaseOrderLineElement do begin

          // New custom tag
          Item.Get(Get_ItemNumber());
          SetValue('SpecialEquipmentCode', Item."Special Equipment Code");

          // Sort by custom tag
          Set_Sorting1(GetValue('SpecialEquipmentCode'));
     end;
end;


How it works behind the scenes

The "sorting" tags determines the sorting on mobile as part of Order Lines GetOrderLines Response.

  • These examples affects the sorting value indirectly by affecting the looping of the record.
  • The sorting value is automatically calculated as a result of of the looping order.

  




Order Lines on the mobile device.