Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
Description
Excerpt |
---|
Examples of sorting Order Lines. |
Flow of events
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.
Description
Excerpt |
---|
Examples of sorting Order Lines. |
This information applies to all Planned functions.
There are two events for sorting order lines:
- 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 field/tag to sort exists as a field in the Element table
- 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
Expand | ||
---|---|---|
| ||
See more: Planned Functions |
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).
- Use
Change sorting direction
- Use
.Ascending(true/false)
-function.Filter by label (Content by label) showLabels false max 152 showSpace false sort title title Available events cql label = "bc" and label = "orderlines" and label = "onaftersetcurrentkey" and label = "integrationevent"
- Use
Sorting on Custom fields
Use.OnAfterSetFrom-events.
Change sorting key
- Use
Set_Sorting1()-
function.Filter by label (Content by label) showLabels false max
150 showSpace false sort title title Available events cql label = "bc" and label = "orderlines" and label = "
onaftersetfrom" and label = "integrationevent"
- Use
Sorting on Custom fields
Use.OnAfterSetFrom-events.
For this task you can use an OnAfterSetCurrentKey event.Change sorting key
UseChange sorting direction
- This is done in two steps:
- Use OnAfterSetFrom[ and the
Set_Sorting1()
-function.
Filter by label (Content by label) showLabels false max 150 showSpace false sort title cql label = "bc" and label = "orderlines" and label = "onaftersetfrom" and label = "integrationevent" Change sorting direction
- This is done in two steps:
- Use OnAfterSetFrom[ and the
Set_Sorting1()
-function. - 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: Sort by Item No.
- Change key to existing field "ItemNumber" on the base element
- Change sorting direction to "Descending"
- Use OnAfterSetCurrentKey and the
.Ascending()
-function.
- Use OnAfterSetCurrentKey and the
Helper Functions
The event parameter "_BaseOrderLineElementView" includes five sorting functions Set_Sorting1..5
, which 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::Codeunit, Codeunit::"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 ReceivePick", 'OnGetReceiveOrderLinesOnGetPickOrderLines_OnAfterSetCurrentKeyOnAfterSetFromAnyLine', '', true, true)]
localprocedure MyOnGetReceiveOrderLines My2aOnGetPickOrderLines_OnAfterSetCurrentKeyOnAfterSetFromAnyLine(_RecRef: RecordRef; var _BaseOrderLineElementViewBaseOrderLineElement: Record "MOB Ns BaseDataModel Element")
begin
begin
// Pad the text values with zeros to get the correct numeric sorting order
_BaseOrderLineElementView.SetCurrentKey(ItemNumber);
_BaseOrderLineElementView.Ascending(false_BaseOrderLineElement.Set_Sorting1(_BaseOrderLineElement.Get_Quantity().PadLeft(10, '0'));
end;
Example: Sort by Quantity
- Since Quantity is a number formatted as text, we need to pad the values with zeros to get the correct numeric sorting order
For this task you must use the OnAfterSetFrom event.
Change to decending order
You can skip this subscriber if you want regular ascending order
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Pick", 'OnGetPickOrderLines_OnAfterSetFromAnyLineOnAfterSetCurrentKey', '', true, true)]
local procedure My2OnGetPickOrderLines My2bOnGetReceiveOrderLines_OnAfterSetFromAnyLineOnAfterSetCurrentKey(_RecRef: RecordRef; var _BaseOrderLineElementBaseOrderLineElementView: 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;
Example
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::Codeunit, Codeunit::"MOB WMS Receive", 'OnGetReceiveOrderLines_OnAfterSetFromAnyLine', '', true, true)]
local procedure OnGetReceiveOrderLines_OnAfterSetFromAnyLine(_RecRef: RecordRef; var _BaseOrderLineElement: Record "MOB Ns BaseDataModel Element")
var
Item: Record Item;
begin
with _BaseOrderLineElement do begin
// New custom tagfield
Item.Get(Get_ItemNumber());
SetValue('SpecialEquipmentCode', Item."Special Equipment Code");
// Sort by custom tagfield
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.
Filter by label (Content by label) | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Order Lines on the mobile device.