Sample Definition to Shows Success or Failure Message for an Action
Define a function, in this case, to handle incoming mobile links in the Consumer Goods mobile app and show the appropriate message to the user. The showMessageBox function shows a message to the user based on the success or failure of an action.
Required Editions
Available in: Lightning Experience Available in: Enterprise and Unlimited Editions that have Consumer Goods Cloud enabled |
-
In Visual Studio Code based Modeler, define an action named
ShowMessageBoxat src/FWDashboard/PR/FWDashboard_FWUserWelcome/FWDashboard_FWUserWelcomeProcess.processflow.xml.The
ShowMessageBoxaction calls theProcessContext::CardController.showMessageBoxmethod with parameterssuccessanddatafrom the event, and transitions to theShowFWUserWelcomeUIaction. It also specifies that thelinkLaunchEventexternal event triggers theShowMessageBoxaction.<Action name="ShowMessageBox" actionType="LOGIC" call="ProcessContext::CardController.showMessageBox"> <Parameters> <Input name="success" value="event.success" /> <Input name="data" value="event.data" /> </Parameters> <TransitionTo action="ShowFWUserWelcomeUI" /> </Action> </Actions> </Body> <ExternalEvents> <Event name="linkLaunchEvent" action="ShowMessageBox" /> </ExternalEvents> </Process> - Save your changes.
-
Define the logic for the
ShowMessageBoxfunction in thesrc/Utilities/BO/BoCockpitHelper/Mv2/BoCockpitHelper.ShowMessageBox.bl.jscontract.In this example, the
showMessageBoxfunction is defined to show a message to the user corresponding to the success or failure of an action. When the user action is successful, the message shows the requested data. If the action fails, the function returns an error message. The function returns the promise when the user completes the action on the message box.function showMessageBox(success, data){ var me = this; ///////////////////////////////////////////////////////////////////////// // Add your customizing javaScript code below. // ///////////////////////////////////////////////////////////////////////// var promise=when.resolve(); var buttonValues = {}; let message = ""; buttonValues[Localization.resolve("OK")] = "ok"; if(success){ message = `payload: ${JSON.stringify(data)}` } else{ message = `error: ${JSON.stringify(data)}` } promise = MessageBox.displayMessage(Localization.resolve("LinkLaunchEvent_Title"), message, buttonValues); /* ////////////////////////////////////////////////////////////////////////// // Add your customizing javaScript code above. // ////////////////////////////////////////////////////////////////////////// */ return promise; } - Save your changes.
-
Create a URL or QR code to test
linkLaunchEvent.-
Define a payload. For example,
{"name": "Test", "id": 123}. -
Encode the payload in the simulator app browser's developer console using this
JavaScript code.
let payload = {"name":"Test","id":123} let encodedPayload = btoa(Array.from(new TextEncoder().encode(JSON.stringify(payload)),(byte) => String.fromCodePoint(byte)).join("")) let mobileLinkURL = `cgcloud://share?payload=${encodedPayload}` -
Construct the mobile link URL with the encoded payload. For example,
cgcloud://share?payload=eyJuYW1lIjoiVGVzdCIsImlkIjoxMjN9
-
Define a payload. For example,
-
To build your contracts, run
sf mdl build. -
Test the mobile link in a web browser.
- Navigate to the application dashboard in the simulator app.
- In the Developer console, select Top.
-
Copy and run the
window.handleOpenURL(mobileLinkURL)command to simulate the mobile link. For example,window.handleOpenURL('cgcloud://share?payload=eyJuYW1lIjoiVGVzdCIsImlkIjoxMjN9')
Verify that a dialog box appears in the app showing the payload as text. -
Test the QR code in the Consumer Goods mobile app.
- Use a tool to create a QR code for the payload URL.
- Open the user welcome page in the mobile app.
- Scan the QR code from the mobile app and verify that a dialog box appears in the app showing the payload as text.

