Info | ||
---|---|---|
| ||
|
...
Steps with no "conditions" are better created using OnAddStepsToAnyHeader-events, i.e. OnGetReceiveOrderLines_OnAddStepsToAnyHeader
Examples
Two examples are shown below. In both examples:
...
Table of Contents | ||||||
---|---|---|---|---|---|---|
|
Example 1:
...
Add extra steps for a single document source (WarehouseReceiptHeader)
This This example describes how to implement extra steps for a single document source for a planned a planned document type (i.e. implement "Warehouse Receipts" for Receive, but not "Purchase Orders", "Transfer Orders" and "Sales Return Orders").
If you are implementing changes for multiple document sources, see "Example 2: Implement extra steps for all document sources (AnyHeader)".
This example is for Warehouse Receipts, but similar events exists exist for any of the planned document types (Receive, Pick, Put-away, Ship, Move, Count).
Step 1.1 -
...
Add radiobutton step (today, yesterday, other)
This step is always displayed,
Use OnGetReceiveOrderLines_OnAddStepsToAnyHeader to add a RadioButton step
The step is created for Warehouse Receipts only.
...
// OnGetReceiveOrderLines
// Create a RadioButton step in the default header collector (for warehouse receipts only)
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Receive", 'OnGetReceiveOrderLines_OnAddStepsToAnyHeader', '', true, true)]
local procedure MyOnGetReceiveOrderLines_OnAddStepsToAnyHeader(_RecRef: RecordRef; var _StepsElement: Record "MOB Steps Element")
begin
if _RecRef.Number() <> Database::"Warehouse Receipt Header" then
exit;
_StepsElement.Create_RadioButtonStep(10000, 'MyPostingDateRadioButtonStep');
_StepsElement.Set_header('Posting Date');
_StepsElement.Set_listValues('Today;Yesterday;Other date');
_StepsElement.Set_defaultValue('Today');
end;
Step 1.2 - Interrupt posting (conditionally) to pick posting date from a calendar
...
// OnPostReceiveOrder
// Create a conditional step on posting based on collected value from the 'MyPostingDateRadioButtonStep' created above
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Receive", 'OnPostReceiveOrder_OnAddStepsToWarehouseReceiptHeader', '', true, true)]
local procedure MyOnPostReceiveOrder_OnAddStepsToWarehouseReceiptHeader(var _OrderValues: Record "MOB Common Element"; _WhseReceiptHeader: Record "Warehouse Receipt Header"; var _StepsElement: Record "MOB Steps Element")
begin
// Break when any option different from 'Other date' was selected in the 'MyPostingDateRadioButtonStep'
if _OrderValues.GetValue('MyPostingDateRadioButtonStep') <> 'Other date' then
exit;
// Break if new datestep for 'Other date' is already collected to prevent infinite loop
if _OrderValues.HasValue('MyPostingDate') then
exit;
// Create a new date step for manually selecting Posting Date
_StepsElement.Create_DateStep(10000, 'MyPostingDate');
_StepsElement.Set_header('Posting Date');
_StepsElement.Set_minDate(Today() - 10);
_StepsElement.Set_maxDate(Today());
end;
Step 1.3 - Set Posting Date
...
// OnPostReceiveOrder
// Set new posting date including using a value from conditional step 'MyPostingDate'
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Receive", 'OnPostReceiveOrder_OnBeforePostWarehouseReceipt', '', true, true)]
local procedure MyOnPostReceiveOrder_OnBeforePostWarehouseReceipt(var _OrderValues: Record "MOB Common Element"; var _WhseReceiptHeader: Record "Warehouse Receipt Header")
var
PostingDate: Date;
begin
case _OrderValues.GetValue('MyPostingDateRadioButtonStep') of
'Today':
PostingDate := Today();
'Yesterday':
PostingDate := Today() - 1;
'Other date':
PostingDate := _OrderValues.GetValueAsDate('MyPostingDate', true);
end;
if (PostingDate <> 0D) and (PostingDate <> _WhseReceiptHeader."Posting Date") then
_WhseReceiptHeader.Validate("Posting Date", PostingDate);
end;
Example 2:
...
Add extra steps for all document sources (AnyHeader)
This example describes how to implement extra steps for planned document types with multiple document sources (i.e. implement "Warehouse Receipts" and "Purchase Orders" for Receive).
If you are implementing changes only for a specific specific document source, see "Example 1: Implement extra steps for a single document source (WarehouseReceiptHeader)".
...
Create new "unconditional" RadioButton step using the OnGetReceiveOrderLines_OnAddStepsToAnyHeader-event. The step are created for "Warehouse Receipt" and "Purchase Order" but excluded for "Sales Return Order" or "Transfer Order"
// OnGetReceiveOrderLines
// Create a step in the default header collector (displayed for "Warehouse Receipt" and "Purchase Order", but not "Transfer Order" or "Sales Return Order")
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Receive", 'OnGetReceiveOrderLines_OnAddStepsToAnyHeader', '', true, true)]
local procedure MyOnGetReceiveOrderLines_OnAddStepsToAnyHeader(_RecRef: RecordRef; var _StepsElement: Record "MOB Steps Element")
begin
if (_RecRef.Number() in [Database::"Warehouse Receipt Header", Database::"Purchase Header"]) then begin
_StepsElement.Create_RadioButtonStep(10000, 'MyPostingDateRadioButtonStep');
_StepsElement.Set_header('Posting Date');
_StepsElement.Set_listValues('Today;Yesterday;Other date');
_StepsElement.Set_defaultValue('Today');
end;
end;
Step 2.2 - Interrupt posting (conditionally) to pick posting date from a calendar
...
// OnPostReceiveOrder
// Create a conditional step on posting based on collected value from the 'MyPostingDateRadioButtonStep' created above
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Receive", 'OnPostReceiveOrder_OnAddStepsToAnyHeader', '', true, true)]
local procedure MyOnPostReceiveOrder_OnAddStepsToAnyHeader(var _OrderValues: Record "MOB Common Element"; _RecRef: RecordRef; var _StepsElement: Record "MOB Steps Element")
begin
// Break when any option different from 'Other date' was selected in the 'MyPostingDateRadioButtonStep'
if _OrderValues.GetValue('MyPostingDateRadioButtonStep') <> 'Other date' then
exit;
// Break if new datestep for 'Other date' is already collected to prevent infinite loop
if _OrderValues.HasValue('MyPostingDate') then
exit;
// Create a new date step for manually selecting Posting Date
_StepsElement.Create_DateStep(10000, 'MyPostingDate');
_StepsElement.Set_header('Posting Date');
_StepsElement.Set_minDate(Today() - 10);
_StepsElement.Set_maxDate(Today());
end;
Step 2.3 - Set Posting Date
...
// OnPostReceiveOrder
// Set new posting date including using a value from conditional step 'MyPostingDate'. Step can exist only for "Warehouse Receipt" or "Purchase Order"
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Receive", 'OnPostReceiveOrder_OnBeforePostAnyOrder', '', true, true)]
local procedure MyOnPostReceiveOrder_OnBeforePostAnyOrder(var _OrderValues: Record "MOB Common Element"; var _RecRef: RecordRef)
var
WhseReceiptHeader: Record "Warehouse Receipt Header";
PurchHeader: Record "Purchase Header";
PurchRelease: Codeunit "Release Purchase Document";
PostingDate: Date;
begin
case _OrderValues.GetValue('MyPostingDateRadioButtonStep') of
'Today':
PostingDate := Today();
'Yesterday':
PostingDate := Today() - 1;
'Other date':
PostingDate := _OrderValues.GetValueAsDate('MyPostingDate', true);
end;
case _RecRef.Number() of
Database::"Warehouse Receipt Header":
begin
_RecRef.SetTable(WhseReceiptHeader);
if (PostingDate <> 0D) and (PostingDate <> WhseReceiptHeader."Posting Date") then
WhseReceiptHeader.Validate("Posting Date", PostingDate);
_RecRef.GetTable(WhseReceiptHeader);
end;
Database::"Purchase Header":
begin
_RecRef.SetTable(PurchHeader);
PurchRelease.Reopen(PurchHeader);
PurchRelease.SetSkipCheckReleaseRestrictions();
PurchHeader.SetHideValidationDialog(true); // same behavior when reprocessing from queue ie. no "change exchange rate" confirmation
PurchHeader.Validate("Posting Date", PostingDate);
PurchRelease.Run(PurchHeader);
_RecRef.GetTable(PurchHeader);
end;
end;