• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • Synchronization
    • CSPro Statements and Functions
    • Text Templates
    • Templated Reporting System
    • HTML, Markdown, and JavaScript Integration
    • Action Invoker
      • Overview
      • Execution Environments
      • Security, Resource Management, and Formatting Options
      • Base Actions
      • Application Namespace
      • Clipboard Namespace
      • Data Namespace
      • Dictionary Namespace
      • File Namespace
      • Hash Namespace
      • Localhost Namespace
      • Logic Namespace
      • Message Namespace
      • Network Namespace
      • Path Namespace
      • Settings Namespace
      • Sqlite Namespace
      • Sync Namespace
        • Sync Action Invoker Namespace
        • Sync.connect Action
        • Sync.disconnect Action
        • Sync.sendMessage Action
        • Sync.syncParadata Action
      • System Namespace
      • UI Namespace
    • Appendix
  • <CSEntry>
  • <CSBatch>
  • <CSTab>
  • <DataManager>
  • <TextView>
  • <TblView>
  • <CSFreq>
  • <CSDeploy>
  • <CSPack>
  • <CSDiff>
  • <CSConcat>
  • <Excel2CSPro>
  • <CSExport>
  • <CSIndex>
  • <CSReFmt>
  • <CSSort>
  • <ParadataConcat>
  • <ParadataViewer>
  • <CSCode>
  • <CSDocument>
  • <CSView>
  • <CSWeb>

Sync.connect Action

Format
d = CS.Sync.connect(connection := ...)
ArgumentDescriptionTypes / Required
connectionThe synchronization connection string specifying the synchronization service.string, object
required
Description
The Sync.connect action connects to a synchronization service, initiating a synchronization session. Once a session is created, you can synchronize:
  • Messages using Sync.sendMessage.
  • Paradata using Sync.syncParadata.
The session is active until it is closed using Sync.disconnect.
The argument connection is a synchronization connection string, generally a server URL or text identifying the service. The connection string contains information about the resource that CSPro will connect to, and any additional parameters (such as a username and password). Connection strings can be specified as a single string or as an object (with the rules for each described here). Details about properties specific to each synchronization service are available on the documentation describing each of the services that CSPro supports:
Synchronization ServiceExample Connection String
Bluetooth"Bluetooth"
CSWeb"https://example.org/csweb/api"
Dropbox"Dropbox"
FTP"ftpes://example.org"
Local Files"file:///C:/surveys/ftp-server"
This action is similar to the CSPro logic function syncconnect. When using actions, multiple synchronization sessions can be created, whereas using CSPro logic, there is only one session per call to syncconnect.
Return Value
The action returns a numeric resource ID that is used to identify this synchronization session in calls to future Sync actions.
Exceptions
The action throws an exception if any of its arguments are not specified in a valid form, or if:
  • There is a network error while connecting to the synchronization service.
  • The service rejected the connection (e.g., the user does not have a valid password or permissions).
Example (JavaScript)
let syncId;

// connect to CSWeb, supplying the username and password
CS.Sync.connectAsync({
    connection: {
        url: 
"https://example.org/csweb/api",
        username: 
"jackw",
        password: 
"MyPa$$w0rd!"
    }
})
.then(id => {
   
// store the resource ID that identifies this synchronization connection
    syncId = id;

   
// send a message to the server
    return CS.Sync.sendMessageAsync({
        syncId: syncId,
        name: 
"Demonstrating Sync.sendMessage at: " + new Date().toString()
    });
})
.then(response => {
    print(
"Successfully sent a message and received: " + JSON.stringify(response));
})
.
finally(() => {
   
// close the synchronization connection
    if( syncId != undefined ) {
       
return CS.Sync.disconnectAsync({
            syncId: syncId
        });
    }
})
.
catch(error => {
    print(
"Error syncing: " + error);
})
See also: Sync Action Invoker Namespace, Sync.disconnect Action, SyncConnect Function