OnGetReferenceData_OnAddDataTables
Use this event to
Create new DataTables ("ListData") that can be used from Steps and HeaderConfigurations.
DataTables are static data in Reference Data, meaning they are loaded on login and cannot change dynamically.
Description
A DataTable is a lists of "entries" sharing a common DataTableId, usually used to fill choices in dropdown-lists at the Mobile Device. DataTables can be referenced from Steps or HeaderConfigurations.
See also: OnGetReferenceData_OnAfterAddDataTableEntry
DataTable or listValues?
An alternative to DataTables is listValues that has advantages and disadvantages as compared to DataTables:
DataTable | listValues |
---|---|
Static, loaded only once at login | Can be dynamic, is created at time of XmlResponse |
Can be reused, is referenced only by its key (DataTableId) | Lists must be created and sent with XmlResponse |
Most efficient, is created and loaded only once at login | Less efficient, in particular if lists are large |
Can contain multiple fields per entry ie. Code and Name | Contains only one field per entry |
Requires this addtional eventsubscriber to create the DataTable | Requires no extra eventSubscriber to create the listValues |
Consider using Steps.Create_ListStepFromListValues()
or HeaderField.Create_ListFieldFromListValues()
if your lists are short, only requires one field per entry - or needs to be dynamic.
Template
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Reference Data", 'OnGetReferenceData_OnAddDataTables', '', true, true)]
local procedure OnGetReferenceData_OnAddDataTables(var _DataTable: Record "MOB DataTable Element"; _MobileUserID: Code[50])
begin
_DataTable.InitDataTable('MyCustomDataTableId'); // Replace with your own dataTable identifier to be used with Set_dataTable(...) from Steps and HeaderConfigurations
// Create your DataTable entries here
// ...
;
end;
Example (1)
// [Example] 01 - Create new custom DataTable based on BC table using a Create_XXX template
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Reference Data", 'OnGetReferenceData_OnAddDataTables', '', true, true)]
local procedure My01OnGetReferenceData_OnAddDataTables(var _DataTable: Record "MOB DataTable Element"; _MobileUserID: Code[50])
var
CountryRegion: Record "Country/Region";
begin
_DataTable.InitDataTable('MyCountries');
if CountryRegion.FindSet() then
repeat
_DataTable.Create_CodeAndName(CountryRegion.Code, CountryRegion.Name);
until CountryRegion.Next() = 0;
end;
Example (2)
// [Example] 02 - Create new custom DataTable based on with no use of templates
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Reference Data", 'OnGetReferenceData_OnAddDataTables', '', true, true)]
local procedure My02OnGetReferenceData_OnAddDataTables(var _DataTable: Record "MOB DataTable Element"; _MobileUserID: Code[50])
var
CountryRegion: Record "Country/Region";
begin
_DataTable.InitDataTable('MyCountryDetails');
if CountryRegion.FindSet() then
repeat
_DataTable.Create();
_DataTable.SetValue('Code', CountryRegion.Code);
_DataTable.SetValue('EUCode', CountryRegion."EU Country/Region Code");
until CountryRegion.Next() = 0;
end;
Example (3)
// [Example] 03 - Create new custom DataTable based on optionfield
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Reference Data", 'OnGetReferenceData_OnAddDataTables', '', true, true)]
local procedure My03OnGetReferenceData_OnAddDataTables(var _DataTable: Record "MOB DataTable Element"; _MobileUserID: Code[50])
var
SalesHeader: Record "Sales Header";
MobCommonMgt: Codeunit "MOB Common Mgt.";
MobToolbox: Codeunit "MOB Toolbox";
OptionIndex: Integer;
begin
_DataTable.InitDataTable('MyDocumentTypes');
for OptionIndex := MobToolbox.AsInteger(SalesHeader."Document Type"::Quote) to MobToolbox.AsInteger(SalesHeader."Document Type"::"Return Order") do begin
SalesHeader."Document Type" := MobCommonMgt.AsSalesDocumentTypeFromInteger(OptionIndex);
_DataTable.Create();
_DataTable.SetValue('DocumentType', Format(SalesHeader."Document Type"));
end;
end;
More examples
There are no items with the selected labels at this time.
Version History
Version | Changes |
---|---|
MOB5.15 | Introduced (supersedes OnGetReferenceData_OnAfterAddListDataAsXml) |
MOB5.26 | Parameter _MobileUserID added. |