Add action to context menu

Introduction

This article describes how to add a new custom action to the context or action menus.

In this example a menu item is added to the Pick order lines list, to send instructions to a Pick Robot to fetch an item from warehouse and move to the physical pick area. While no instructions are actually issued to a Pick Robot in this example, it will show how to create the neccessary pages and how to trigger custom code in the backend.


... the "Send to Robot"-option will open a new "Send To Robot"-page, including a "SUBMIT" that will trigger our mocked code in the backend.


Overview

The steps to create a new menu action are (discussed in details below):

  1. New Configuration Header for "Send To Robot"-page
  2. Associate configuration header with new page in application.cfg
  3. Add action to existing "BurgerMenu"
  4. Handle new RegistrationType in codeunit "MOB WMS Adhoc Registr.
  5. Testing the solution


Example

Step 1: New Configuration Header for "Send To Robot"-page

To be able to submit a request to the backend, a page must exist including visible fields that holds the information needed by the backend. The SUBMIT request will include the visible fields and its values.

In this example, a reference to the source document line is needed by the Pick Robot. Therefore, a new configuration header must include the OrderBackendID and LineNumber. Addtional fields (ItemNumber, DisplayLine1 etc.) could be added to the configuration header as well, to help user identify the line being handled. However, for this example we included only the neccessary two fields.


codeunit 6181381 "MOB WMS Reference Data"
local procedure AddConfiguration(var XMLResponseData: XmlNode);
begin   
  .....
  CreateConfig(XMLResponseData,REGISTER_IMAGE_HEADER);
  CreateConfig(XMLResponseData,CREATE_ASSEMBLY_ORDER_HEADER);
  CreateConfig(XMLResponseData,ADJUST_QTY_TO_ASSEMBLE_HEADER);
  CreateConfig(XMLResponseData,ATTACHMENTS_HEADER);
  CreateConfig(XMLResponseData,'SendToPickRobotHeader');	//<----
end;


codeunit 6181381 "MOB WMS Reference Data"
procedure CreateHeaderConfiguration(var XMLResponseData: XmlNode; "Key": Text[50]);
begin
  .....
  ADJUST_QTY_TO_ASSEMBLE_HEADER:
    BEGIN
      AddAdjustQtyToAssembleHeaderValues(XMLCDataSection);
    END;
  ATTACHMENTS_HEADER:
    BEGIN
      AddAttachmentsHeaderValues(XMLCDataSection);
    END;
  'SendToPickRobotHeader': 									//<----
      AddSendToPickRobotHeaderValues(XMLCDataSection);	    //<----
end;


codeunit 6181381 "MOB WMS Reference Data"
local procedure AddSendToPickRobotHeaderValues(var XmlCDataSection: XmlCdata);
begin
    // Add the header lines
    AddConfHeaderTextValue(XmlCDataSection,
                           1,                 //id
                           'OrderBackendID',  //name
                           MobWmsLanguage.GetMessage('BATCH_NAME') + ':',  //label
                           100,               //label width
                           false,             //clear on clear
                           false,             //accept barcode
                           20,                //length
                           false,             //optional
                           '',                //search type
                           '',                //eanAi
                           true);             //locked


    // Line Number
    AddConfHeaderTextValue(XmlCDataSection,
                            2,                 //id
                            'LineNumber',  //name
                            MobWmsLanguage.GetMessage('LINENUMBER') + ':',  //label
                            100,               //label width
                            false,             //clear on clear
                            false,             //accept barcode
                            20,                //length
                            false,             //optional
                            '',                //search type
                            '',                //eanAi
                            true);             //locked
end;


The code above will add a new entry to Reference Data, identified by new Key "SendToPickRobotHeader".




Step 2: Add new page

Next, our new configuration header "SendToPickRobotHeader" needs to be associated with a new page in application.cfg. 

Modify the Mobile Configuration Files


application.cfg
<page id="SendToPickRobot" type="UnplannedItemRegistration" icon="">
	<title defaultValue="Send To Robot"/>
	<unplannedItemRegistrationConfiguration type="SendToPickRobotRegistrationType" useRegistrationCollector="false">
		<header configurationKey="SendToPickRobotHeader" automaticAcceptAfterLastScan="true"/>
	</unplannedItemRegistrationConfiguration>
</page>


Step 3: Add action

The new action is added to the existing PickLines-page.

This will associate the action to the new page we created above.


Add this line to "PickLines"-pagen.

<open id="SendToPickRobot" icon="" title="Send To Robot" />

Modify the  Mobile Configuration Files


application.cfg
   <page id="PickLines" type="OrderLines" icon="mainmenupick">
      <title defaultValue="@{PagePickOrderLinesTitle}"/>
      <orderLinesConfiguration>
        <service id="Pick"/>
        <list listId="OrderLinesWithImages"/>
        <viewRegistrations title="@{OrderLinesRegistrationMenuItem}" navigateTo="ViewRegistrations" enabled="true"/>
        <deleteOrderRegistrations title="@{OrderLinesDeleteAllOrderRegistrationsMenuItem}" enabled="true"/>
        <totePicking allowManualSelection="true">
          <currentTote show="true" useLabelPrefix="false"/>
        </totePicking>
        <scanToSelectBehaviour gs1SearchTerm="Item" behaviour="Auto"/>
      </orderLinesConfiguration>
      <actions>
        <showImage id="1" enabled="true" imageProperty="ItemImage" title="@{MenuItemShowImageTitle}"/>
		<open id="SendToPickRobot" icon="" title="Send To Robot" />
      </actions>
    </page>   


Step 4: Handle new RegistrationType in codeunit "MOB WMS Adhoc Registr."

The type="UnplannedItemRegistration" (qua existing Document Type setup) will trigger the handler codeunit "MOB WMS Adhoc Registr.". 

The SUBMIT-button for the page is associated to new RegistrationType type="SendToPickRobotRegistrationType".


As per our "Send To Robot"-page defnition the submit button will submit a DocumentType='PostAdhocRegistration', RegistrationType='SendToPickRobotRegistrationType' request.

We need to catch this RegistrationType and forward to our own new code in the backend;

codeunit 6181380 "MOB WMS Adhoc Registr."
procedure PostAdhocRegistration();
var
    [.....]
begin
    [.....]
	MobWMSToolbox."CONST::Internal"():
		begin
			Status := Internal(XMLRequestDoc, RegistrationTypeTracking);
			MOBToolbox.CreateSimpleResponse(XMLResultDoc, Status);
		end;
	// >> SendToPickRobot
	'SendToPickRobotRegistrationType':
		begin
			Status := SendToPickRobot(XMLRequestDoc, RegistrationTypeTracking);
			MOBToolbox.CreateSimpleResponse(XMLResultDoc, Status);
		end;
	// << SendToPickRobot
     [.....]
end;


This sample backend code will only mock a reply, but do nothing else.  The OrderBackendID and LineNumber is parsed from the request, and a succes response is created. (the MObXmlMgt.XPathInnerText() function call from the example requires MOB4.38 or later).

codeunit 6181380 "MOB WMS Adhoc Registr."
    // >> SendToPickRobot
    local procedure SendToPickRobot(XMLRequestDoc: XmlDocument; var ReturnRegistrationTypeTracking: Text[200]): Text[60];
    var
        MobXmlMgt: Codeunit "MOB XML Management";
        OrderBackendID: Code[23];
        LineNumber: Integer;
    begin
        // Disable the locktimeout to prevent timeout messages on the mobile device
        LOCKTIMEOUT(false);

        MobDocQueue.LoadXMLRequestDoc(XMLRequestDoc);
        OrderBackendID := MobXmlMgt.XPathInnerText(XMLRequestDoc, '//req:OrderBackendID');
        Evaluate(LineNumber, MobXmlMgt.XPathInnerText(XMLRequestDoc, '//req:LineNumber'));

        // Mock something that can be recognized at the mobile device for this example
        ReturnRegistrationTypeTracking := StrSubstNo('MOCK Fetch OrderBackendID %1, LineNumber %2', OrderBackendID, LineNumber);
        exit('MOCK PickRobot instructions was issued');
    end;
    // << SendToPickRobot


Step 5: Testing the solution

Submitting from the "Send To Robot" page should now display the message we returned from our custom "SendToPickRobot()"-method:


The mobile document queue shows the registration type tracking information we returned:


Associated Request:

Associated Response: