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 39 Next »

Description

Examples of sorting Order list

 

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.


Sorting on multiple document sources

All except "Ship" have multiple document sources.

I.e. the default sorting for Receive orders list at the mobile device is:

  • First, Warehouse Receipts
  • Then Purchase Orders
  • Then Transfer Orders
  • Then Sales Return Orders

... so essentially "grouping" orders by the four document sources that can all be in the same list (with each "group" being internally ordered by document numbers).


When working with custom sorting you must consider.

Should the filter be applied across all document types?

  • Yes: Use the generic "Any"-event
  • No: Use the document-specific event(s)


Sorting on Existing fields ("OnAfterSetCurrentKey"-events)

Example 1

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

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


Example 2

  • Change key to existing field "Order No."

[EventSubscriber(ObjectType::CodeunitCodeunit::"MOB WMS Receive", 'OnGetReceiveOrders_OnAfterSetCurrentKey''', true, true)]
procedure OnGetReceiveOrders_OnAfterSetCurrentKey(var _BaseOrderElementView: Record "MOB Ns BaseDataModel Element")
begin
     _BaseOrderElementView.SetCurrentKey(BackendID);
     _BaseOrderElementView.Ascending(true);
end;


Sorting on Custom fields ("OnAfterSetFrom"-events)

Note. For this task: you must both:

  1. Set the value
  2. Enable sorting on it

Example 1: 

Sort all picks by "Assigned User ID"

  • Sort on "Assigned User ID'" from the source RecordRef
  • For this "AnyEvent" the RecordRef can be "Warehouse Activity Header", "Sales Header", "Purchase Header" or "Transfer Header" depending on what documents are available to pick


    [EventSubscriber(ObjectType::CodeunitCodeunit::"MOB WMS Pick", 'OnGetPickOrders_OnAfterSetFromAnyHeader''', true, true)]
    local procedure MySortByCustomTag_OnGetPickOrders_OnAfterSetFromAnyHeader(_RecRef: RecordRefvar _BaseOrderElement: Record "MOB Ns BaseDataModel Element")
    var
        DataTypeManagement: Codeunit "Data Type Management";
        NewFieldRef: FieldRef;
    begin
        if DataTypeManagement.FindFieldByName(_RecRef, NewFieldRef, 'Assigned User ID'then
            _BaseOrderElement.SetValue('AssignedUserID''Assigned to: ' + CopyStr(NewFieldRef.Value()1, NewFieldRef.Length()));

        _BaseOrderElement.Set_Sorting1(_BaseOrderElement.GetValue('AssignedUserID'));
    end;

Example 2:

Sort only Warehouse Picks by "Assigned User ID"

  • Sort on "Assigned User ID'" from the Source  Warehouse Activity Header


    [EventSubscriber(ObjectType::CodeunitCodeunit::"MOB WMS Pick", 'OnGetPickOrders_OnAfterSetFromWarehouseActivityHeader''', true, true)]
    local procedure My02GetPickOrders_OnAfterSetFromWarehouseActivityHeader(_WhseActHeader: Record "Warehouse Activity Header"; var _BaseOrderElement: Record "MOB Ns BaseDataModel Element")
    begin
        _BaseOrderElement.SetValue('AssignedUserID''Assigned to: ' + _WhseActHeader."Assigned User ID");
        _BaseOrderElement.Set_Sorting1(_BaseOrderElement.GetValue('AssignedUserID'));
    end;

  • No labels