There are two possible session IDs. When a new form is created, a local client session ID is created. This a unique ID that will live with the life of the form. You can get to this ID through the SessionData Class. This ID can be accessed in Datapath filenames and the Descriptor using [SESSIONID]; and can be accessed in script using
Dim localID As String
Dim sd As SessionData = _form.SessionData(0)
localID = sd.SessionID
A server-side session ID, ServerSesssionID, is also created when the form is sent to the server. If you need this, you could create a hidden field and then set that field via the ServerQueuing event that is triggered as the form is sent to the server. This is not a permanent ID, as it does change every time it syncs with the server. A possible solution would be:
<MiCode(FormScriptEventType.ServerQueuing)> _
Public Sub Form_ServerQueuing(ByVal e As ServerQueuingEventArgs)
_Hidden.Value = e.ServerSessionID
End Sub
In summary, if you need to both IDs, it may be best to combine both of these solutions into something like:
<MiCode(FormScriptEventType.ServerQueuing)> _
Public Sub Form_ServerQueuing(ByVal e As ServerQueuingEventArgs)
_Hidden.Value = e.ServerSessionID
End Sub
<MiCode(FormScriptEventType.AfterDataPathsRun)> _
Public Sub Form_AfterDataPathsRun(ByVal e As AfterDataPathsRunEventArgs)
Dim localID As String
Dim serverID As String
If _form.SessionData.Count > 0 Then
Dim sd As SessionData = _form.SessionData(0)
localID = sd.SessionID
End If
serverID = _Hidden.Value
End Sub