Skip to main content

MobileRPCRegistry220FDW

The central dispatcher for all mobile RPC requests. It parses the incoming JSON, hydrates the state, and routes the call to the correct service handler. This codeunit is the key extensibility point -- downstream developers never modify it but subscribe to its integration events to register their own service implementations.

Overview

  • Object type: Codeunit
  • Object ID: 73167878
  • Access: Public
  • Namespace: Aptean.Mesh.SDUI

The registry handles two built-in methods (GetPageFlow and GetUserInformation) directly. All other method calls are routed to service implementations via the OnResolveService integration event.

Dispatch Lifecycle

Dispatch Flow
Mobile Client
Sends HTTP POST with JSON-RPC payload
|v
BCRPC220FDW (API Page)
Calls SetRequest() + OnRun
|v
MobileRPCRegistry220FDW.Dispatch()
Routes by method name:
├──GetPageFlow──▶return page bundle directly
├──GetUserInformation──▶return user info directly
└──Any other method──▶service registry lookup (see below)
|vany other method
Service Registry Lookup
Queries table by Bundle ID + Service Code → returns Codeunit ID
|v
OnResolveService Event
Your subscriber checks the Codeunit ID, sets Service := this
|v
Your AL Codeunit (implements IBCRPC220FDW)
Registry calls Service.RPC(State)
Reads State.Method(), executes business logic
Returns JsonObject ──▶ client renders response
  1. An external caller sets the raw JSON request via SetRequest()
  2. The codeunit is invoked (its OnRun trigger fires Dispatch())
  3. Dispatch() parses the JSON and calls State.Hydrate()
  4. Based on State.Method():
    • 'GetPageFlow' -- returns the page flow configuration for the active app bundle
    • 'GetUserInformation' -- returns the current user's name, company, and warehouse locations
    • Any other value -- looks up the service in the Mobile Service Registry table and fires OnResolveService
  5. The caller retrieves the response via GetResponse()

Public Methods

SetRequest

procedure SetRequest(Request: Text)

Sets the raw JSON-RPC request text to be dispatched. Call this before running the codeunit.

Parameters:

NameTypeDescription
RequestTextThe raw JSON-RPC request string from the mobile client

Example:

var
Registry: Codeunit MobileRPCRegistry220FDW;
begin
Registry.SetRequest(IncomingJsonText);
Registry.Run();
ResponseJson := Registry.GetResponse();
end;

GetResponse

procedure GetResponse(): JsonObject

Returns the JSON-RPC response after dispatching is complete.

Returns: JsonObject -- the response payload containing the result key.


Bundle

procedure Bundle(): Guid

Returns the app bundle GUID from the current request. Delegates to State.BundleOrEmpty().

Returns: Guid -- the bundle identifier, or an empty GUID if not present.


Service

procedure Service(): Code[50]

Returns the service code from the current request. Delegates to State.ServiceOrEmpty().

Returns: Code[50] -- the service code (e.g., 'PUTAWAY'), or empty if not present.


Method

procedure Method(): Text[50]

Returns the RPC method name from the current request. Delegates to State.Method().

Returns: Text[50] -- the method name (e.g., 'Initialize', 'GetPageFlow').

Integration Events

OnResolveService

[IntegrationEvent(false, false)]
local procedure OnResolveService(
CodeunitId: Integer;
var Service: Interface IBCRPC220FDW;
var IsServiceResolved: Boolean)

Fired when the registry needs to resolve a codeunit ID to a service implementation. This is the primary extensibility point for Aptean Mesh. Every service codeunit must subscribe to this event to make itself discoverable.

Parameters:

NameTypeDirectionDescription
CodeunitIdIntegerInThe codeunit ID from the Mobile Service Registry table
ServiceInterface IBCRPC220FDWvar (out)Set this to your codeunit instance (this) when the ID matches
IsServiceResolvedBooleanvar (out)Set to true after assigning Service to signal the registry that the service was found

Event Subscriber Pattern

Every service codeunit that implements IBCRPC220FDW must include an event subscriber like this:

[EventSubscriber(ObjectType::Codeunit, Codeunit::MobileRPCRegistry220FDW,
OnResolveService, '', false, false)]
local procedure ResolveMyService(
CodeunitId: Integer;
var Service: Interface IBCRPC220FDW;
var IsServiceResolved: Boolean)
begin
if IsServiceResolved then
exit;
if CodeunitId <> Codeunit::"My Service" then
exit;
Service := this;
IsServiceResolved := true;
end;

Key rules:

  1. Check IsServiceResolved first -- another subscriber may have already handled the request. Exit early to avoid overwriting.
  2. Match on CodeunitId -- compare against your codeunit's own object ID using Codeunit::"My Service".
  3. Set Service := this -- return yourself as the interface implementation.
  4. Set IsServiceResolved := true -- tells the registry that the service was successfully resolved.

Error Messages

The registry produces the following errors when resolution fails:

ConditionError
Missing bundle in paramsInvalid request: Missing "bundle" in params.
Missing service in paramsInvalid request: Missing "service" in params.
Service code not found in registry tableService '%1' is not configured for bundle '%2'. Please register it in Mobile Service Setup.
No subscriber resolved the codeunitNo service implementation found for Codeunit ID %1 (Service: %2). Ensure the codeunit subscribes to OnResolveService event.
Invalid JSON bodyParse error: Invalid JSON format.
Client version too old (for GetPageFlow)Your app is outdated. Please update to the latest version from the Play Store.
Root page not configured (for GetPageFlow)Root Page ID is not configured in the App Bundle. Please set a Root Page ID in the Mobile App Bundle setup.

Complete Registration Example

This end-to-end example shows how to register a custom service with the Aptean Mesh framework:

Step 1: Configure in Business Central

Open Mobile App Bundles, select your bundle, then open Mobile Service Setup. Add a row with your service code and codeunit ID.

Step 2: Implement the codeunit

codeunit 50100 "My Putaway Service" implements IBCRPC220FDW
{
[EventSubscriber(ObjectType::Codeunit, Codeunit::MobileRPCRegistry220FDW,
OnResolveService, '', false, false)]
local procedure ResolveService(
CodeunitId: Integer;
var Service: Interface IBCRPC220FDW;
var IsServiceResolved: Boolean)
begin
if IsServiceResolved then
exit;
if CodeunitId <> Codeunit::"My Putaway Service" then
exit;
Service := this;
IsServiceResolved := true;
end;

procedure RPC(var State: Codeunit MobileRPCState220FDW) ResponseJson: JsonObject
begin
case State.Method() of
'Initialize':
Initialize(State);
'ScanBin':
ScanBin(State);
'Confirm':
Confirm(State);
end;
ResponseJson := State.Serialize();
end;

local procedure Initialize(var State: Codeunit MobileRPCState220FDW)
begin
// Load document, build initial UI state
end;

local procedure ScanBin(var State: Codeunit MobileRPCState220FDW)
begin
// Validate scanned bin code against warehouse setup
end;

local procedure Confirm(var State: Codeunit MobileRPCState220FDW)
begin
// Post the putaway and return a success result
State.SetResult('posted', 'true');
end;
}

See Also