Case
Excerpt |
---|
Scan ExpirationDate as custom format YYYYMM when items is received from any Vendor. |
...
Scan ExpirationDate as new text field in custom format YYYYMM when items is received from any Vendor. The change must be in effect for all four receive document types (:
- Warehouse Receipt
...
- Purchase Order
...
- Transfer Receipt
...
- Sales Return Order
...
Disable standard Expiration Date step due to this always being validated as date format, then create a new custom step validated from a regular expression. This regular expression must validate year as "20 + two digits" and month as "0 + one digit" or "10", "11" or "12".
When saving RegistrationData, the new custom ExpirationDate should be used when creating the RegistrationData-entry. The RegistrationData."Expiration Date" will be used by Mobile WMS posting functions with no further changes.
Example
//
// Create new RegistrationCollectorConfiguration-Key in reference data with one new step named "CustomExpirationDate"
//
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Reference Data", 'OnGetReferenceData_OnAfterAddRegistrationCollectorConfigurationsAsXml', '', true, true)]
local procedure OnGetReferenceData_OnAfterAddRegistrationCollectorConfigurationsAsXml(var _XmlResponseData: XmlNode)
var
MobXmlMgt: Codeunit "MOB XML Management";
XmlConfigurationNode: XmlNode;
XmlKeyNode: XmlNode;
XmlValueNode: XmlNode;
XmlCDataSection: XmlCdata;
begin
// Add the mandatory nodes
MobXmlMgt.AddElement(_XmlResponseData, 'Configuration', '', '', XmlConfigurationNode);
MobXmlMgt.AddElement(XmlConfigurationNode, 'Key', 'MyCustomSteps', '', XmlKeyNode);
MobXmlMgt.AddElement(XmlConfigurationNode, 'Value', '', '', XmlValueNode);
// Add the CDATA section to the Value-Node
XmlCDataSection := GetOrderLineExtraInfoCDataSection();
MobXMLMgt.NodeAppendCData(XmlValueNode, XmlCDataSection);
end;
local procedure GetOrderLineExtraInfoCDataSection() XmlCDataSection: XmlCdata
var
MobXmlMgt: Codeunit "MOB XML Management";
MobConfTools: Codeunit "MOB WMS Conf. Tools";
DummyXmlDocument: XmlDocument;
RegexExpr: Text[1024];
begin
// Create an empty CDATA section to add the registrationCollectorConfiguration XML to
MobXmlMgt.NodeCreateCData(DummyXmlDocument, XmlCDataSection, '');
// Create the start tags of the configuration xml. These must be closed afterwards.
MobXMLMgt.NodeAppendCDataText(XmlCDataSection, '<registrationCollectorConfiguration>');
MobXMLMgt.NodeAppendCDataText(XmlCDataSection, '<steps>');
// Add the actual steps
RegexExpr := '(20[0-4]\d)(0[1-9]|1[0-2])'; // "20"+ remaining two digits in year then two digit month (0+single digit or 10, 11 or 12)
MobConfTools.RC_Std_Parms(10000, 'MyExpirationDate', 'Expiration Date (YYYYMM)', 'Expiration Date:', 'Expiration Date in format YYYYMM');
MobConfTools.RC_Ext_Parms_InputFormat(RegexExpr);
MobConfTools.RC_Text_CData(XmlCDataSection, '', 6);
MobXMLMgt.NodeAppendCDataText(XmlCDataSection, '</steps>');
MobXMLMgt.NodeAppendCDataText(XmlCDataSection, '</registrationCollectorConfiguration>');
exit(XmlCDataSection);
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.
if Get_RegisterExpirationDate() = 'true' then begin
Set_RegisterExpirationDate(false); // Disable the standard (date format) expiration date step
Create_StepsByReferenceDataKey('MyCustomSteps', true); // This key must include MyExpirationDate-step but may include other steps as well
end;
end;
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Toolbox", 'OnSaveRegistrationValue', '', true, true)]
procedure OnSaveRegistrationValue(_Path: Text; _Value: Text; var _MobileWMSRegistration: Record "MOB WMS Registration"; var _IsHandled: Boolean)
var
Year: Integer;
Month: Integer;
begin
if _Path <> 'MyExpirationDate' then
exit;
if _Value <> '' then begin
Evaluate(Year, CopyStr(_Value, 1, 4));
Evaluate(Month, CopyStr(_Value, 5, 2));
_MobileWMSRegistration."Expiration Date" := DMY2Date(01, Month, Year);
end else
_MobileWMSRegistration."Expiration Date" := 0D;
_IsHandled := true;
end;