Preface
In Microsoft Dynamics 365 Business Central the extension model is object-based.
You create new objects, and extend existing objects depending on what you want your extension to do. The underlying Mobile WMS source code is now sealed and can no longer be modified directly.
This necessitated a refactoring of our model for making custom changes to the Xml Requests and Xml Responses which are being communicated between the mobile devices and the Mobile WMS backend in Business Central. As a part of this refactoring, we are introducing new "accessor" layer to manipulate the Xml content, but with no need to manipulate the Xml Documents directly as to date.
Past model (C/SIDE)
Changes to XML Response was made directly in handler codeunits, e.g. "MOB WMS Receive" etc.
Changes implied writing directly to the XML output, and required knowledge of the XML element, case sensitive tags and using correct namespaces.
Example:
// The choices are: None, Warn, Block
// MobXMLMgt.AddElement(XMLOrderLine, 'UnderDeliveryValidation', 'Warn', BaseDataModelNS, XMLCreatedNode);
MobXMLMgt.AddElement(XMLOrderLine, 'UnderDeliveryValidation', 'Block', BaseDataModelNS, XMLCreatedNode);
New model (AL)
Changes to XML Responses now requires Event Subscriber procedures to be declared in your own code.
Changes are now strictly in your own project, and the underlying Mobile WMS source code is no longer modified.
You can subscribe to (among others) a number of "On After Set From XXX"-events .
Rather than manipulating the Xml output directly, values is are now set in new "accesssor accessor table" that hides all underlying Xml considerations. By using Set/Get accessor methods in these accessor tables, content is automatically formatted and inserted at correct nodes and namespaces in the Xml documents.
Example:
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Receive", 'OnGetReceiveOrderLines_OnAfterSetFromAnyLine', '', true, true)]
procedure OnReceiveOnAfterSetFromAnyLine(_RecRef: RecordRef; var _BaseOrderLineElement: Record "MOB Ns BaseDataModel Buffer")
begin
// Under-/OverDeliveryValidation - The choices are: None, Warn, Block
_BaseOrderLineElement.Set_UnderDeliveryValidation('Block');
end;
Accessor class (C#)
New "accessor tables" has been introduced to Mobile WMS. The accessor tables concept is derived from C# property classes.
...
Code Block | ||||
---|---|---|---|---|
| ||||
class Person { private string name; // the name field public string Name // the Name property { get { return name; } set { name = value; } } } |
Accessor table (AL)
In AL, codeunits (the AL equivalent for C# classes) cannot be parameters to procedures/methods, unlike in C# (newer BC versions indeed supports codeunits as parameters, but this is not the case for every BC version we support). This makes AL codeunits a poor choice when temporary data needs to be stored and transferred between codeunits and procedures. Instead, we have introduced new "accesssor tables" in Mobile WMS, basically being C# style acccessor classes, but implemented at table level.
Three new accessor tables has been introduced. Each table corresponds to a specfic part of the Mobile WMS Xml schema, and makes available get/set accessors for each node in corresponding namespaces.
- table 6181380 "MOB Ns Resp Element"
- table 6181381 "MOB Ns BaseDataModel Element"
- table 6181382 "MOB Ns WhseInquery Element"
...
"MOB Ns Resp Element" is the most simple of those, and includes only get/set-methods for one predefined property "description". Also, every accessor table includes get/set-methods to add custom elements not being a part of the standard schema, including as CDATA elements:
- Get_description(): Text
- Set_description(NewValue: Text)
- GetValue(_PathToGet: Text): Text
- SetValue(_PathToSet: Text; _NewValue: Text)
SetValueAsCData(_PathToSet: Text; _NewXmlCData: XmlCData)
SetValueAsCData(_PathToSet: Text; _NewCDataValue: Text)
Ns BaseDataModel Element (Accessor table, AL)
The "MOB Ns BaseDataModel Element" is used to build "<BaseOrder>" and "<BaseOrderLine>" elements in the BaseDataModel namespace. It is the most frequently used new accessor table by far. All 'GetXXXOrdes" and "GetXXXOrderLines" requests will make this accessor table available from a number of new "OnAfterSetFrom[...]"-events.
...
... for new (custom) tags:
- GetValue(_PathToGet: Text): Text
- SetValue(_PathToSet: Text; _NewValue: Text)
SetValueAsCData(_PathToSet: Text; _NewXmlCData: XmlCData)
SetValueAsCData(_PathToSet: Text; _NewCDataValue: Text)
Ns WhseInquiry Element (Accessor table, AL)
The "MOB Ns WhseInquiry Element" is used to build "<LookupResponse>"-elements in the WarehouseInquiryDataModel namespace. It is used from the "MOB WMS Lookup" codeunit.
...
... for new (custom) tags with no preexisting Get/Set-methods:
- GetValue(_PathToGet: Text): Text
- SetValue(_PathToSet: Text; _NewValue: Text)
SetValueAsCData(_PathToSet: Text; _NewXmlCData: XmlCData)
SetValueAsCData(_PathToSet: Text; _NewCDataValue: Text)