Mobile Data StudioObject Model › Replying to a Telegram

Telegrams allow live communication between mobile devices and the server from within a session. Data can be exchanged in both directions.

As an example use-case, a project may have a page that allows the user to scan a barcode with the Barcode point. A Telegram point could then send the scanned barcode to the server, which could look up the scanned barcode value in an external database using ADO. The server could then send a reply to the client, automatically filling in a series of other points with information from the database.

Similar functionality could be achieved by packaging all of the data into the project ahead of time using an Ultra Drop point, with automatic filter lookup. However with the telegram model, the project does not need to contain the entire database.

Simple Reply

First, a simple example that sends a reply to the mobile device when a telegram is received:

Sub OnTelegram ( Telegram )

Set reply = Project.NewTelegram ' Create a reply
reply("TelegramName") = Telegram("TelegramName") ' Use the same telegram name
reply.SendToClient Telegram.UnitID ' Send the reply to the same device

End Sub

Live Data Lookup

Now a more complex example, implementing the use case described above where product data is looked up in a database and returned to the mobile device:

Sub OnTelegram ( Telegram )

Set reply = Project.NewTelegram ' Create a reply

reply("TelegramName") = Telegram("TelegramName") ' Use the same telegram name
reply("ScannedBarcode") = Telegram("ScannedBarcode") ' Echo the barcode back in the reply

Set conn = CreateObject( "ADODB.Connection" ) ' Connect to an external database
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Path\Database.mdb"

' Query for the product by its barcode
query = "SELECT * FROM ProductTable WHERE Barcode='" & Telegram("ScannedBarcode") & "'"

Set rs = CreateObject( "ADODB.Recordset" )
rs.Open query, db, 3, 3, 1 ' (1) because we want to perform a query

If Not rs.EOF Then ' If the row exists

' Copy some data from the database into the reply telegram
reply("Description") = rs("Description")
reply("Price") = rs("Price")

End If

rs.Close ' Close the recordset

reply.SendToClient Telegram.UnitID ' Send the reply to the same device

End Sub