Altova MobileTogether Designer

A message is sent from MobileTogether Server to a webpage in the following stages:

 

1.The workflow's Embedded Message Back action sends the message to the IFrame in the form of a serialized JSON string. You specify the message to send in the action.

2.When the message reaches the IFrame, it is forwarded to the webpage, where an event listener picks up the message event and calls a function to process the message. You can register an event listener for the message event as follows: window.addEventListener('message', ProcessReturnMsg)

3.The function (ProcessReturnMsg in the example above) takes the message event in the form of a deserialized JSON object as its parameter. You can now access the object as usual and use it in the HTML page. For example:

function ProcessReturnMsg(m) {

msgVar = m.data.json.books

...

}

 

For more information, see the descriptions of AddEventListener and MessageEvent at the Mozilla Developer Network website.

 

Example

The design contains a $MT_EMBEDDEDMESSAGE page source with the structure shown in the screenshot below. Note that the root element of this page source will always be named json (because this is a JSON page source).

MTDEWSExJSONPgSrc

We can send the entire contents of this page source (or a part of it) as a message event to the solution in the IFrame. This could be done, for example, if a button in the design has an Embedded Message Back action set for its OnClicked event (see screenshot below). In the XPath expression below, note that it is the contents of $MT_EMBEDDEDMESSAGE node (the json node and its contents) that is sent as the message event.

MTActionEmbeddedMsgBack

In the HTML page, we can now register an event listener: window.addEventListener('message', ProcessReturnMsg)

 

We can then access the object as usual and use it in the HTML page. For example:

function ProcessReturnMsg(m) {

  msgVar = m.data.json.books

  /* 'm' is the HTML message event that is passed to ProcessReturnMsg */

  /* 'data' belongs to the event and holds the message returned by the MT action */

  /* 'json' is the JSON object that is contained in the message */  

  ...

    }

 

In the example above, the content of books will be saved to msgVar.

 

© 2018-2024 Altova GmbH