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
SetRequest() + OnRunService := thisService.RPC(State)State.Method(), executes business logicJsonObject ──▶ client renders response- An external caller sets the raw JSON request via
SetRequest() - The codeunit is invoked (its
OnRuntrigger firesDispatch()) Dispatch()parses the JSON and callsState.Hydrate()- 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
- 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:
| Name | Type | Description |
|---|---|---|
Request | Text | The 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:
| Name | Type | Direction | Description |
|---|---|---|---|
CodeunitId | Integer | In | The codeunit ID from the Mobile Service Registry table |
Service | Interface IBCRPC220FDW | var (out) | Set this to your codeunit instance (this) when the ID matches |
IsServiceResolved | Boolean | var (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:
- Check
IsServiceResolvedfirst -- another subscriber may have already handled the request. Exit early to avoid overwriting. - Match on
CodeunitId-- compare against your codeunit's own object ID usingCodeunit::"My Service". - Set
Service := this-- return yourself as the interface implementation. - Set
IsServiceResolved := true-- tells the registry that the service was successfully resolved.
Error Messages
The registry produces the following errors when resolution fails:
| Condition | Error |
|---|---|
Missing bundle in params | Invalid request: Missing "bundle" in params. |
Missing service in params | Invalid request: Missing "service" in params. |
| Service code not found in registry table | Service '%1' is not configured for bundle '%2'. Please register it in Mobile Service Setup. |
| No subscriber resolved the codeunit | No service implementation found for Codeunit ID %1 (Service: %2). Ensure the codeunit subscribes to OnResolveService event. |
| Invalid JSON body | Parse 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
- IBCRPC220FDW -- the interface that service codeunits implement
- MobileRPCState220FDW -- the state object passed into every
RPC()call