The DataSync Agent can be set up to replicate table records from a Service Now instance to local file(s) on the machine where the DataSync Agent is running. This can be useful for the case where you have a separate application that is able to read files to import data.
Records can be saved in CSV, JSON, and XML formats and each record is inserted into the file (i.e. the previous version is not updated) when the Agent processes a message.
Prerequisites
First, you will need to set up the Perspectium DataSync Agent.
You should also stop running your DataSync Agent before making any Agent configuration changes.
Procedure
To enable file replication for the DataSync Agent, follow these steps:
Navigate to the directory where you saved your agent.xml file when installing your DataSync Agent.
Within the <task> tag, nest the following directives with your choice of how you want to save your records:
- All Records in One File
- One Record per File
- Records to Multiple Files
These three options are detailed below:
Save the changes you've made to your agent.xml and close the file.
An example agent.xml configuration for saving all records to a single file is shown below:
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?> <config> <agent> <max_reads_per_connect>10</max_reads_per_connect> <polling_interval>20</polling_interval> <subscribe> <task> <task_name>file_subscribe</task_name> <message_connection password="password" user="user">https://<customer>.perspectium.net</message_connection> <instance_connection password="password" user="user">https://<instance>.service-now.com</instance_connection> <decryption_key>The cow jumped over the moon</decryption_key> <handler>com.perspectium.replicator.file.XMLFileSubscriber</handler> <file_name>records.xml</file_name> <files_directory>/Users/user/Downloads</files_directory> <exclude_xml_header/> <buffered_writes>250</buffered_writes> </task> </subscribe> </agent> </config>
An example agent.xml configuration for saving one record per file is shown below:
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?> <config> <agent> <max_reads_per_connect>10</max_reads_per_connect> <polling_interval>20</polling_interval> <subscribe> <task> <task_name>file_subscribe</task_name> <message_connection password="password" user="user">https://<customer>.perspectium.net</message_connection> <instance_connection password="password" user="user">https://<instance>.service-now.com</instance_connection> <decryption_key>The cow jumped over the moon</decryption_key> <handler>com.perspectium.replicator.file.XMLFileSubscriber</handler> <one_record_per_file/> <files_directory>/tmp</files_directory> <file_prefix>records</file_prefix> <file_suffix>.xml</file_suffix> </task> </subscribe> </agent> </config>
An example agent.xml configuration for saving records to multiple files is shown below:
<?xml version="1.0" encoding="ISO-8859-1" ?> <config> <agent> <!-- the following subscribe fragment defines subscribing class --> <!-- and its arguments --> <subscribe> <task> <task_name>test_file_subscriber</task_name> <message_connection password="password_here" user="admin" queue="psp.in.meshlet.example">https://<customer>.perspectium.net</message_connection> <instance_connection password="Adminadmin1" user="admin">https://<instance>.service-now.com</instance_connection> <max_reads_per_connect>1</max_reads_per_connect> <polling_interval>3</polling_interval> <decryption_key>Example_decryption_key_here</decryption_key> <handler>com.perspectium.replicator.file.JSONFileSubscriber</handler> <buffered_writes>10</buffered_writes> <files_directory>/Users/You/Downloads/Example</files_directory> <file_prefix>$table_$d{yyyyMMdd}_$i</file_prefix> <file_suffix>.json</file_suffix> <file_max_size>50KB</file_max_size> <translate_newline>%13</translate_newline> <separate_files>table</separate_files> <enable_audit_log/> <close_file_interval>180</close_file_interval> </task> </subscribe> </agent> </config>
After configuring your agent.xml file to enable file replication, start running your DataSync Agent again.