Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
title | Version requirement |
---|
Description
Excerpt |
---|
Adding a new custom Lookup function with one "Header field" to show simple lookup response. |
Prerequisites
Please read Lookup functions to ensure this flow suits your requirement.
This example
- Will result in an custom This example will result in a lookup function accessible by a menuitem on the context menu of "Pick Orders" Action.
- The lookup will return information from the BC standard field displays "Work Description" in from a the Sales Order header.
- - but this example can used display any information like Comments, Notes, Instructions etc.
See Lookup Functions to ensure this flow suits your requirement
Step 1: Defining a new custom lookup page
This part requires you to edit the Mobile Configuration FileFiles
Add this section in the <pages> tag.
Note that we use two special Notable properties:
<header> has two properties in the <header> element to achieve the desired behavior on the device.
More details: Lookup Mobile Configuration
automaticAcceptOnOpen =- automaticAcceptOnOpen = Defines if the values in the header should be automatically accepted
- If true, hide
- (collapse) the header when "Accept"-button is pressed at Mobile Device
<onResultSelected>
- navigateTo= Used to navigate to another page when selecting the lookup result (Null in this example)
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<!-- Custom --> <page id="WorkDescription" type="Lookup" icon="stopwatch"> <title defaultValue="Work Description"/> <lookupConfiguration type="WorkDescription" useRegistrationCollector="false"> <header configurationKey="WorkDescriptionHeader" automaticAcceptOnOpen="true" hideAfterAccept="true"/> <onResultSelected enabled="true" navigateTo="null"/> <list listId="Lookup"/> </lookupConfiguration> </page> <!-- Custom --> |
Add this section to the <actions> tag in the Pick page.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<!-- Custom --> <open id="WorkDescription" icon="stopwatch" title="Work Description"/> <!-- Custom --> |
Image Added
Step 2: Define Header and
header fieldsFor this example we onlya Header Field
We only need to add one field containing the BackendID.
(When using same fieldname as in the page that is linked from, it will get automatically populated on the device)
Subscribe to this event
OnGetReferenceData_OnAddHeaderConfigurations
called "ReferenceID".
This value will automatically be filled in, because "ReferenceID" is already present on all Planned Functions order and orderline -responses.
"ReferenceID" is basically a RecordID which identifies an Order or Orderline.
Using event OnGetReferenceData_OnAddHeaderConfigurations
// Step 2 Create new custom ConfigurationKey
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Reference DataMOB WMS Reference Data", 'OnGetReferenceData_OnAddHeaderConfigurations', '', truetrue, truetrue)]
local procedure OnGetReferenceData OnGetReferenceData_OnAddHeaderConfigurations(var _HeaderFields: Record "MOB HeaderField ElementMOB HeaderField Element")
begin
// Identifier for new ConfigurationKey - replace by your own key name
Identifier for new ConfigurationKey - replace by your own key name
_HeaderFields.InitConfigurationKey('WorkDescriptionHeader');
// Add headerConfiguration elements here
Add Header Fields
_HeaderFields.Create_TextField_ReferenceID(1, 'BackendID');
end;
Step 3: Handle lookup
When the Header has been accepted, a final request ); // "ReferenceID" is basically a RecordID which is present on all Planned functions. This is perfect for identifying the Sales Order No. or Whse. Activity
end;
Step 3: Handle lookup
When the Header has been accepted, a final request is made to lookup the information ("Lookup")
In this step you must handle your custom lookup named "WorkDescription" and read the collected values (BackendID), and return the lookup request.
Subscribe to this event
.
We will return a "LookupResponseElement" containing only DisplayLine1.
Using event OnLookupOnCustomLookupType...
// Step 3 Handle lookup
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS LookupMOB WMS Lookup", 'OnLookupOnCustomLookupType', '', truetrue, truetrue)]
local procedure MyOnLookupOnCustomLookupType OnLookupOnCustomLookupType(_MessageId: Guid; _LookupType: Text; var _RequestValues: Record "MOB NS Request Element"; var _XmlResultDoc: XmlDocument; var "MOB NS Request Element"; var _LookupResponseElement: Record"MOB NS WhseInquery Element"; var _RegistrationTypeTracking: Text; var _IsHandled: Boolean)
begin
if _LookupType <> LookupType <> 'WorkDescription' then
exit;
if _IsHandled then
exit; WorkDescriptionLookup(_LookupType, _RequestValues, _XmlResultDoc); _IsHandled := true;
end;
local procedure WorkDescriptionLookup(var _LookupType: Text; var _RequestValues: Record "MOB NS Request Element"; var _XmlResultDoc: XmlDocument)
var
TempLookupResponseElement: Record "MOB NS WhseInquery Element" temporary;
MobWmsLookup: Codeunit "MOB WMS Lookup";
MobToolbox: Codeunit "MOB Toolbox";
MobXmlMgt: Codeunit "MOB Xml Management";
XmlResponseData: XmlNode;
BackendId: Code[20];
begin
// Read Request
Evaluate(BackendId, _RequestValues.Get_BackendID());
// Initialize the response xml
MobToolbox.InitializeResponseDocWithNS(_XmlResultDoc, XmlResponseData, CopyStr(MobXmlMgt.NS_WHSEMODEL(), 1, 1024));
// Create new Response Element
TempLookupResponseElement.Create();
TempLookupResponseElement.Set_DisplayLine1(GetWorkDescription(BackendId));
TempLookupResponseElement.Save();
MobWmsLookup.AddLookupResponseElements(_LookupType, XmlResponseData, TempLookupResponseElement);
end;
// Simple sample Procedure to read Work Description from Source Document.
local procedure GetWorkDescription(_BackendId: Code[20]): Text
var
WhseActHeader: Record "Warehouse Activity Header";
SalesHeader: Record "Sales header";
begin
if WhseActHeader.Get(WhseActHeader.Type::"Invt. Pick", _BackendId) then
if SalesHeader.Get(SalesHeader."Document Type"::Order, WhseActHeader."Source No.") then
exit(SalesHeader.GetWorkDescription());
end;
New menu item
Image Removed
"Work Description"" is shown in the context menu on the Pick Orders list.
Display Custom Look page
Image Removed
// Create new Response Element
_LookupResponseElement.Create();
_LookupResponseElement.Set_DisplayLine1(GetWorkDescription(_RequestValues.Get_ReferenceID())); // Use "ReferenceID" value from the Request values
_IsHandled := true;
end;
local procedure GetWorkDescription(_RecordID: Text) ReturnValue: Text
var
WhseActHeader: Record "Warehouse Activity Header";
WhseActLine: Record "Warehouse Activity Line";
SalesHeader: Record "Sales Header";
MobToolbox: Codeunit "MOB Toolbox";
RecRef: RecordRef;
begin
MobToolbox.ReferenceIDText2RecRef(_RecordID, RecRef);
case RecRef.Number() of
Database::"Sales Header":
begin
// Pick directly for Sales Order
RecRef.SetTable(SalesHeader);
ReturnValue := SalesHeader.GetWorkDescription();
end;
Database::"Warehouse Activity Header":
begin
RecRef.SetTable(WhseActHeader);
// Inventory Pick
if WhseActHeader.Type = WhseActHeader.Type::"Invt. Pick" then
if SalesHeader.Get(SalesHeader."Document Type"::Order, WhseActHeader."Source No.") then
ReturnValue := SalesHeader.GetWorkDescription();
// Warehouse Pick
if WhseActHeader.Type = WhseActHeader.Type::"Pick" then begin
WhseActLine.SetRange("Activity Type", WhseActLine."Activity Type"::Pick);
WhseActLine.SetRange("No.", WhseActHeader."No.");
WhseActLine.SetRange("Source Type", Database::"Sales Line");
if WhseActLine.FindFirst() then
if SalesHeader.Get(SalesHeader."Document Type"::Order, WhseActLine."Source No.") then
ReturnValue := SalesHeader.GetWorkDescription();
end;
end;
end;
if ReturnValue = '' then
ReturnValue := 'No Work Description for ' + _RecordID;
end;
"ReferenceID" vs. "BackendID" / "OrderBackendID"
If "ReferenceID" is not present in the XML Request, you can use the default "BackendID" / "OrderBackendID" -values.
Depending on the context where you are adding the new menu Item, the XML Response will be different:
- Action from "Orders List" e.g "GetPickOrders":
- <BackendID> is used
- Evaluate(BackendId, _RequestValues.Get_BackendID());
- <BackendID> is used
- Use the new action on an "Order Lines List" e.g. "GetPickOrderLines"
- <OrderBackendID> is used
New menu item
Image Added
"Work Description" is shown in the context menu on the Pick Orders list
Lookup result
Image Added
Message is displayed