Case
Excerpt |
---|
A customer wishes to start using Item NetWeight and -GrossWeight, but have currently no values registered at the Item Card. Create a temporary customization is to collect these weights when goods are received. |
...
Standard CRONUS Location 'WHITE' can be used for testing the customization.
Example
tableextension 50200 "DEMO Warehouse Receipt Line" extends "Warehouse Receipt Line"
{
fields
{
field(50200; "DEMO Captured NetWeight"; Decimal)
{
Description = 'Mobile WMS DEMO';
Caption = 'Captured NetWeight';
DataClassification = CustomerContent;
}
field(50201; "DEMO Captured GrossWeight"; Decimal)
{
Description = 'Mobile WMS DEMO';
Caption = 'Captured GrossWeight';
DataClassification = CustomerContent;
}
}
}
tableextension 50201 "DEMO Posted Whse. Receipt Line" extends "Posted Whse. Receipt Line"
{
fields
{
field(50200; "DEMO Captured NetWeight"; Decimal)
{
Description = 'Mobile WMS DEMO';
Caption = 'Captured NetWeight';
DataClassification = CustomerContent;
}
field(50201; "DEMO Captured GrossWeight"; Decimal)
{
Description = 'Mobile WMS DEMO';
Caption = 'Captured GrossWeight';
DataClassification = CustomerContent;
}
}
}
codeunit 50719 "DEMO Receive Weight Ext v.5.14"
{
//
// Create new RegistrationCollectorConfiguration-Key in reference data with two steps named: "CustomGrossWeightGrams" and "CustomNetWeightGrams"
//
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Reference Data", 'OnGetReferenceData_OnAddRegistrationCollectorConfigurationOnAddRegistrationCollectorConfigurations', '', true, true)]
local procedure OnGetReferenceData_OnAddRegistrationCollectorConfigurationOnAddRegistrationCollectorConfigurations(var _Steps: Record "MOB Steps Element")
begin
with _Steps do begin
CreateConfigurationKey('CustomWReceiveSteps');
Create_DecimalStep(10000, 'CustomNetWeightGrams');
Set_header('Net Weight (Grams)');
Set_label('Net Weight (Grams):');
Set_helpLabel('Net Weight in Grams per Base Unit of Measure');
Set_minValue(0);
Set_maxValue(100000);
Set_performCalculation(true);
Create_DecimalStep(20000, 'CustomGrossWeightGrams');
Set_header('Gross Weight (Grams)');
Set_label('Gross Weight (Grams):');
Set_helpLabel('Gross Weight in Grams per Base Unit of Measure');
Set_minValue(0);
Set_maxValue(100000);
Set_performCalculation(true);
end;
end;
//
// Add steps referenced by new RegistrationCollectorConfiguration-Key to line steps collectors
//
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Receive", 'OnGetReceiveOrderLines_OnAddStepsToAnyLine', '', true, true)]
procedure OnGetReceiveOrderLines_OnAddStepsToAnyLine(_RecRef: RecordRef; var _BaseOrderLineElement: Record "MOB Ns BaseDataModel Element")
begin
with _BaseOrderLineElement do
// MOB5.11
// Currently the Android Mobile App supports only one "RegisterExtraInfo"-node (one extra RegistrationCollectorConfigurationKey).
// The last subscriber to OnGetReceiveOrderLines_OnAfterAddStepsByReferenceDataKey must set a <RegisterExtraInfo>-key that includes steps for all previous subscribers.
// This is only possible by knowing what other customizations is done and manually create a new RegistrationCollectorConfigurationKey that includes all steps.
//
// In this demo we expect to be only subscriber and throw an error if earlier subscribtions exists by including optional _ErrorIfAlreadyCreated parameter.
// We cannot test if later subcribers is overriding this value we set.
Create_StepsByReferenceDataKey('CustomWReceiveSteps', true);
end;
//
// Handle new step input values by WhseReceiptLine (move captured values to new fields at Whse. Receipt Line)
//
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Receive", 'OnPostReceiveOrder_OnHandleRegistrationForWarehouseReceiptLine', '', true, true)]
procedure OnPostReceiveOrder_OnHandleRegistrationForWarehouseReceiptLine(var _Registration: Record "MOB WMS Registration"; var _WhseReceiptLine: Record "Warehouse Receipt Line")
var
MobWmsToolbox: Codeunit "MOB WMS Toolbox";
RegistrationXmlText: Text;
begin
// Demo: Show content of the "Registration XML" blob -- not needed for the processing below (useful for debugging)
RegistrationXmlText := _Registration.GetRegistrationXmlAsText();
// Parse the xml WmsRegistration by name of the steps declared in GetOrderLineExtraInfoCDataSection() and save value to new fields at WhseReceiptLine
// Includes optional parameter _ErrorIfNotExists since we unconditially expect these two nodes to exist at all line registrations
_WhseReceiptLine."DEMO Captured NetWeight" := MobWmsToolbox.Text2Int(_Registration.GetValue('CustomNetWeightGrams', true));
_WhseReceiptLine."DEMO Captured GrossWeight" := MobWmsToolbox.Text2Int(_Registration.GetValue('CustomGrossWeightGrams', true));
end;
//
// Push new fields at Warehouse Activity Line to Item card using standard posting event
// Using this standard event ensures data written to Item is within same commit at Whse Receipt Line posting
//
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Whse.-Post Receipt", 'OnBeforePostSourceDocument', '', true, true)]
procedure OnWhsePostReceiptOnBeforePostSourceDocument(var WhseRcptLine: Record "Warehouse Receipt Line"; PurchaseHeader: Record "Purchase Header"; SalesHeader: Record "Sales Header"; TransferHeader: Record "Transfer Header")
var
Item: Record Item;
begin
if not (Item.Get(WhseRcptLine."Item No.") and ((WhseRcptLine."DEMO Captured NetWeight" <> 0) or (WhseRcptLine."DEMO Captured GrossWeight" <> 0))) then
exit;
UpdateItemWeights(Item, WhseRcptLine."DEMO Captured NetWeight", WhseRcptLine."DEMO Captured GrossWeight");
Item.Modify();
end;
local procedure UpdateItemWeights(var _Item: Record Item; _NetWeightGrams: Integer; _GrossWeightGrams: Integer)
var
ConversionFactor: Decimal;
begin
// Conversion factor between registrered unit (grams) and item card unit (kg) -- hardcoded for simplification
ConversionFactor := 1000;
// Update item card if new values was provided in the input steps
if _GrossWeightGrams > 0 then
_Item."Gross Weight" := _GrossWeightGrams / ConversionFactor;
if _NetWeightGrams > 0 then
_Item."Net Weight" := _NetWeightGrams / ConversionFactor;
end;
}
Testing your solution
- Register a Warehouse Receipt at a Mobile Device. Two new line steps for NetWeight and GrossWeight should appear. Add both Weights for an item and post the Receipt.
- Run table browser for Posted Whse. Receipt Line (table no. 7319). Your new values should be visible at latest posted receipt:
- Run table browser for Item (table no. 27). Your new values should be recorded at the Item you registered/posted:
...