Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Description

Excerpt

Examples of sorting Order list


Flow of events

...

This information applies to all 

...

Planned functions.


There are two events for sorting orders:

  1. Using OnAfterSetCurrentKey-events
    • Set Sorting Direction
    • Set Sorting Key Fields (Standard fields only)

  2. Using OnAfterSetFrom-events
    • Set Sorting Key Fields (Custom fields)



Expand
titleEvent flow for getting Orders and Lines
  1. ...OnSetFilter-events

    • Reads data from source tables
      • Add Filters
      • Modify Filters


  2. ...OnAfterSetFrom-events

    • Data goes into accessor table "BaseOrderLineElement"
      • Add Data
      • Modify Data
      • Set Sorting Key Fields (Custom fields)


  3. ...OnAfterSetCurrentKey-events

    • Data is sorted
      • Set Sorting Key Fields (ONLY standard fields)
      • Set Sorting Direction


  4. (XML Response is transmitted to the Mobile Device)

See more: Planned Functions


1: Sorting on existing fields 

Use OnAfterSetCurrentKey-events.

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

  • Change sorting direction
    • Use .Ascending(true/false)-function. 
    Use these events:
    • Filter by label (Content by label)
      showLabelsfalse
      showSpacefalse
      cqllabel = "bc" and label = "onaftersetcurrentkey" and label = "integrationevent" and label = "orders"



2: Sorting on

...

custom fields

Use.OnAfterSetFrom-events.

  • Change sorting key 
    • Use Set_Sorting1()-function.
      Filter by label (Content by label)
      showLabelsfalse
      showSpacefalse
      cqllabel = "bc" and label = "orders" and label = "onaftersetfrom" and label = "integrationevent"


  • 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.

Sorting on multiple document sources

All except "Ship" have multiple document sources.


I.e. the default Affect all sources by using "Any"-events

If you work across locations you might also want to filter across all of them

For example, the sorting for Receive orders list at the mobile device is:

...

  1. Warehouse Receipts

...

  1. Purchase Orders

...

  1. Transfer Orders

...

  1. Sales Return Orders

... so essentially "grouping" orders by the All 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 If you filter across all document types?

...

, then use the "Any"-event

...

, else 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"

For this task, you must use the OnAfterSetCurrentKey event.[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

...

Sort lines by your own custom field

("OnAfterSetFrom"-events)

Note. For this task: you must both:

  • You must use the "OnAfterSetFrom"-event
  • both set the value and enable sorting on it

  1. Set the value
  2. Enable sorting on it


Expand
titleSee event parameters
  • _[SourceTable]
    • The source table from where the data is read.
      • This parameter is only for reference.
      • It is not to be modified and filters does not have any effect.

  • _BaseOrderElement
    Helper functions to identify and manipulate the Order-element

    • Set
    • Get
      • Get_Value
        • Get any value already set on the element
      • Get_BackendID
        • Get Order No.
      • Get_RecRefFromReferenceID
        • Get RecordRef to the Order

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 ReceiveMOB WMS Pick", 'OnGetReceiveOrderLinesOnGetPickOrders_OnAfterSetFromAnyLineOnAfterSetFromAnyHeader''', true true, true true)]
procedure OnGetReceiveOrderLines_OnAfterSetFromAnyLine    local procedure MySortByCustomTag_OnGetPickOrders_OnAfterSetFromAnyHeader(_RecRef: RecordRefvar _BaseOrderLineElementBaseOrderElementRecord "MOB Ns BaseDataModel ElementMOB Ns BaseDataModel Element")
    var
        DataTypeManagement:     ItemCodeunit "Data Type Management";
        NewFieldRefRecord ItemFieldRef;
    begin
        if DataTypeManagement.FindFieldByName(_RecRef, NewFieldRef,     with _LineElement do begin
          // New custom tag'Assigned User ID'then
            _BaseOrderElement.SetValue('AssignedUserID''Assigned to: ' + CopyStr(NewFieldRef.Value()1, NewFieldRef.Length()));

          Item.Get(Get_ItemNumber());
          SetValue('SpecialEquimentCode', Item."Special Equipment Code");          // Sort by custom tag
          Set_Sorting1(GetValue('SpecialEquimentCode'));
     end;
end_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;