Sometimes, a developer may need to access their Session's ID on the script side, for example to use it as an output to a table via a custom export.
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. A possible solution considering your end goal would be through a AfterDataPathsRun event, possibly:
<MiCode(FormScriptEventType.AfterDataPathsRun)> _ Public Sub Form_AfterDataPathsRun(ByVal e As AfterDataPathsRunEventArgs) Dim localID As String If _form.SessionData.Count > 0 Then Dim sd As SessionData = CType(_form.SessionData(0), SessionData) localID = sd.SessionID End If End Sub
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 = CType(_form.SessionData(0), SessionData) localID = sd.SessionID End If serverID = _Hidden.Value End Sub