Mobile Data StudioObject Model › Modifying Session Data

A common task is to access and possibly modify session data when a new session arrives on the server from a mobile device.

This should be done in the OnIncomingSession() function in Data Script. This function is run as soon as a new session is received from a mobile device, as the first step in the Data Pathway.

It can access, and potentially modify the session before the rest of the Data Pathway steps run.

If it returns True, processing continues through the rest of the Data Pathway. If it returns False, no further processing of the session occurs.

Reading Session Metadata

The Session object that was received is passed as a parameter to the Data Script OnIncomingSession() function.

The session contains metadata, such as the Session.UnitID property, which identifies the mobile device that sent it:

Function OnIncomingSession ( Session )

sendingUnitID = Session.UnitID
Application.Print "Got a session from " & sendingUnitID
OnIncomingSession = True

End Function

Reading Session Data

It also contains a dictionary of values, where the dictionary keys are the point ID names from the session:

Function OnIncomingSession ( Session )

somePointValue = Session("SomePointIDName")
Application.Print "Session from " & Session.UnitID & " had value " & somePointValue

OnIncomingSession = True

End Function

Making Decisions

The script code could make decisions based on data read from the session:

Function OnIncomingSession ( Session )

somePointValue = Session("SomePointIDName")

If somePointValue = "Yes" Then
Application.Print "Got a good session"
End If

OnIncomingSession = True

End Function

Modifying Session Data

Because the OnIncomingSession() function is the first thing to run when a new session is received, any modifications it makes to the session will be visible to everything that comes later, including outputs to Excel, HTML or XML files, and the Database Window.

Function OnIncomingSession ( Session )

somePointValue = Session("SomePointIDName")

If somePointValue = "Yes" Then
' Change another point value
Session("AnotherPointIDName") = "Success"
End If

OnIncomingSession = True

End Function