This example shows you how to call an external application from within the Swift MEAP™ application.
The example below calls a Web page hosted locally, shows the data in an HTML table, and upon submit redirects to the Swift MEAP™ application showing the original record that was open before the outbound call. The overall steps in this example, which are the typical steps for calling external applications from within the Swift MEAP™ application, are:
- Call the external application from within the Swift MEAP™ application.
- Pass data from the Swift MEAP™ application to the external application.
- Return to the same record that was open in the Swift MEAP™ application before launching the external application.
The following assumptions are made in this example:
- The Contacts module is available.
- A Web container (for example, nodejs) is available, which can listen for HTTP requests.
Preserving the DeviceRowID
Typically, the application which receives the call from Swift MEAP must have the devicerowid in order to query the data source for the actual record. As a result, the devicerowid must be synchronized with the data source as well. The following procedure shows you how to update the devicerowid field and synchronize the changes with the data source.
To update the devicerowid field and synchronize the changes with the data source:
Choose a field in the data source to set aside for storing the devicerowid of a record. For example, use CONTTXT01 which is the field used to store the Description in the Contact module.
Create an onSaveJSON function in the Contact module as follows:
- Start the Admin application.
- Click Map Settings, and then select Module Settings on the vertical application bar.
- Click More next to the Contact module, click JavaScript, and then select Add JavaScript Code.
- Select onSave from the Type drop-down list, and then enter the onSave JavaScript code.
An example of the complete code with header and footer information follows. In this example, the uid and the devicerowid of the newly created Contact record are read and the IDs are passed to the UpdateCRMODDeviceRowId method, which updates the CONTXT01 field with the devicerowid. The devicerowid is synchronized with the Description field in the data source.
<html><head><title>devicerowidExample</title><script type="text/javascript"> function onSaveJSON() { return "[{\"action\":\"select\",\"invoke\":\"updateDSDeviceRowId\",\"parameters\":[{\" modulefields\": [ { \"module\":\"2\", \"fields\":\"uid,devicerowid\"} ],\"filter\":\"2.uid=$2.uid\"} ] } ]"; } function updateDSDeviceRowId(rows) { var jsonscript = "["; if(rows.length > 0){� jsonscript�= "{\"action\":\"update\",\"module\":\"2\",\"uid\":\"" + rows[0]._2.uid + "\",\"fields\":[ { \"field\":\"CONTTXT01\", \"value\":\""+rows[0]._2.devicerowid"\"} ], \"upsync\":\"yes\", \"filter\":\"2.uid ="rows[0]._2.uid"\" }";� }� jsonscript += "]"; return jsonscript; } function onErrorInvoke(rows){� if(rows.length > 0){ window.location="melt://showAlert/"+ rows[0].message;� }� } </script></head><body></body></html>�