Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 73 Next »

Description

Examples of sorting Order Lines.

 

Flow of events




Sorting on Existing fields

Use OnAfterSetCurrentKey-events.



Sorting on Custom fields

Use.OnAfterSetFrom-events.



Helper Functions

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


Example 1: Sort by Item No.

  • Change key to existing field "ItemNumber" on the base element
  • 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 MyOnGetReceiveOrderLines_OnAfterSetCurrentKey(var _BaseOrderLineElementView: Record "MOB Ns BaseDataModel Element")
begin
     _BaseOrderLineElementView.SetCurrentKey(ItemNumber);
     _BaseOrderLineElementView.Ascending(false);
end;
 

Example 2: Sort by Quantity in decending order

For this task you must use the OnAfterSetFrom event

  • Quantity is a number formatted as text, we need to pad the values with zeros to get the correct numeric sorting order

[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Pick", 'OnGetPickOrderLines_OnAfterSetFromAnyLine', '', true, true)]
local procedure My2aOnGetPickOrderLines_OnAfterSetFromAnyLine(_RecRef: RecordRef; var _BaseOrderLineElement: Record "MOB Ns BaseDataModel Element")
begin
    // Pad the text values with zeros to get the correct numeric sorting order
    _BaseOrderLineElement.Set_Sorting1(_BaseOrderLineElement.Get_Quantity().PadLeft(10, '0'));
end;


Change to decending order

You can skip this subscriber if you want regular ascending order


EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Pick", 'OnGetPickOrderLines_OnAfterSetCurrentKey', '', true, true)]
procedure My2bOnGetReceiveOrderLines_OnAfterSetCurrentKey(var _BaseOrderLineElementView: Record "MOB Ns BaseDataModel Element")
begin
    // OPTIONAL: Remove this part if you want regular ascending ordering
    _BaseOrderLineElementView.Ascending(false);
end;


Example 3: Sort by a custom field

  • 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 field
          Item.Get(Get_ItemNumber());
          SetValue('SpecialEquipmentCode', Item."Special Equipment Code");

          // Sort by custom field
          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.

  


See also



Order Lines on the mobile device.




  • No labels