> ## Documentation Index
> Fetch the complete documentation index at: https://docs.arc.cdata.com/llms.txt
> Use this file to discover all available pages before exploring further.

# CSV Connector

> Converts comma-separated values (CSV) files into XML and generates CSV files from XML, enabling bidirectional data transformation within flows.

export const format_1 = "CSV"

export const format_0 = "CSV"

export const DelimitedXmlMapTransformation = ({format = "CSV"}) => <>
    <p>Many data transformation flows use the {format} connector in conjunction with the <a href="/26.3/cloud/en/connectors/xml-map/xml-map">XML Map Connector</a>.</p>

    <p>Often, data enters an Arc flow in {format} format and should exit the flow in some other format (for example, a database insert, an EDI file, or an insert into a CRM or ERP data source), or vice versa. Arc uses a single streamlined approach to these data transformation requirements:</p>

    <ul>
      <li>Model the input format as XML</li>
      <li>Model the output format as XML</li>
      <li>Use the XML Map connector to map between the input XML and the output XML</li>
    </ul>

    <p>Therefore, the {format} connector is commonly adjacent to an XML Map connector in the flow:</p>

    <ul>
      <li>When {format} files are the <em>input</em> to the flow, the {format} connector converts a {format} file to XML and then passes that XML off to the XML Map connector to be transformed</li>
      <li>When {format} files are the <em>output</em> from the flow, the {format} connector receives XML from the XML Map connector and converts it into a {format} file</li>
    </ul>

    <p>An XML Map connector requires a sample XML structure for both the mapping input/source and the mapping output/destination. Use the <a href="#sample-files-tab">Sample Files</a> tab to upload a sample file. Next, connect a {format} connector to an XML Map connector in the flow. This connection can go in either direction: inbound to the XML Map connector, or outbound from the XML Map connector.</p>

    <p>The XML Map connector automatically detects the structure of the test file. Based on where you placed the {format} connector, the file appears in the <strong>Source File</strong> or <strong>Destination File</strong> drop-down menu of the XML Map connector.</p>

    <Note>The structure of this test file should be representative of future files. In other words, all of the {format} files processed by the {format} connector (and then the XML Map connector) should have the same columns as your test file. You might need to set up multiple {format} connectors and multiple XML Map connectors to handle distinct {format} structures.</Note>
  </>;

export const DelimitedPrintView = ({format = "CSV", printPreviewImage}) => {
  const img = printPreviewImage || `${format.toLowerCase()}_print_preview.png`;
  return <>
      <p>When you view a {format} document on the connector <strong>Transactions</strong> tab, you can view it in a print preview format, or as the raw data. By default, the document is shown in the preview format, as shown in the following image:</p>

      <img src={`/public/images/${img}`} width="800" />

      <p>The preview format shows the data in an easy-to-read layout. Use the <strong>Raw View</strong> toggle in the top right corner to view the unformatted document.</p>
    </>;
};

export const DelimitedAutomationSettings = () => <>
    <p><em>Settings related to the automatic processing of files by the connector.</em></p>

    <table>
      <thead>
        <tr><th>Setting</th><th>Description</th></tr>
      </thead>
      <tbody>
        <tr>
          <td><strong>Send</strong></td>
          <td>Whether messages arriving at the connector are automatically processed.</td>
        </tr>
      </tbody>
    </table>
  </>;

export const DelimitedProcessingDelay = () => <table>
    <thead>
      <tr><th>Setting</th><th>Description</th></tr>
    </thead>
    <tbody>
      <tr>
        <td><strong>Processing Delay</strong></td>
        <td>The amount of time (in seconds) by which the processing of files placed in the <strong>Transactions</strong> tab is delayed. This is a legacy setting. Best practice is to <a href="/26.3/cloud/en/flows/designing-a-flow#interacting-with-the-local-file-system">use a File connector</a> to manage local file systems instead of this setting.</td>
      </tr>
    </tbody>
  </table>;

export const DelimitedSampleFiles = () => <>
    <p><em>Uploading a sample file allows for easy mapping in any connected CSV Map or XML Map connectors.</em></p>

    <p>Use the <strong>Sample Files</strong> tab to generate a source or destination XML template for use in a <a href="/26.3/cloud/en/connectors/map">CSV Map</a> or <a href="/26.3/cloud/en/connectors/xml-map/xml-map">XML Map</a> connector. Click <strong>Add Sample File</strong>.</p>

    <ol>
      <li>If you already have an example file that reflects the expected format and structure of your data, choose <strong>File Upload</strong> and browse to your file. Alternatively, select <strong>Manually Create</strong> to create a file directly in the application. If you choose <strong>Manually Create</strong>, give your sample file a name. Click <strong>Next</strong>.</li>
      <li>If you browsed to an existing file, the <strong>View File</strong> tab is populated with its contents. If you chose to manually create a file, enter your sample data on this tab. Click <strong>Next</strong>.</li>
      <li>The <strong>Translate and Preview</strong> tab displays a preview of your sample data converted to XML. When you are satisfied with your sample, click <strong>Add</strong>.</li>
    </ol>
  </>;

export const DelimitedOtherSettings = () => <table>
    <thead>
      <tr><th>Setting</th><th>Description</th></tr>
    </thead>
    <tbody>
      <tr>
        <td><strong>Local File Scheme</strong></td>
        <td>A scheme for assigning filenames to messages that are output by the connector. You can use macros in your filenames dynamically to include information such as identifiers and timestamps. For more information, see <a href="#macros">Macros</a>.</td>
      </tr>
      <tr>
        <td><strong>Line Separator</strong></td>
        <td>The character sequence to use to denote line endings. By default, this is determined by the system, but you can use this setting to override the system behavior. Use <code>CR</code> or <code>\r</code> to denote carriage return, and <code>LF</code> or <code>\n</code> to denote line feed.</td>
      </tr>
    </tbody>
  </table>;

export const DelimitedConnectorSettings = ({format = "CSV"}) => {
  const lower = format.toLowerCase();
  return <table>
      <thead>
        <tr><th>Setting</th><th>Description</th></tr>
      </thead>
      <tbody>
        <tr>
          <td><strong>Column headers present</strong></td>
          <td>Whether the {format} file contains a row of headers providing names or context to the values in the file.</td>
        </tr>
        <tr>
          <td><strong>Record Name</strong></td>
          <td>
            The name of elements representing a row in the {format} file when converting to XML. You can use the following macros: %ConnectorID%, %FilenameNoExt%, %RegexFilename:%, and %Header:%. See <a href={`#converting-${lower}-to-xml`}>Converting {format} to XML</a> for more details.
          </td>
        </tr>
      </tbody>
    </table>;
};

export const DelimitedOverview = ({format = "CSV"}) => {
  const lower = format.toLowerCase();
  return <>
      <p>XML is the primary format that CData Arc uses to manipulate data within a flow. Therefore, it is useful to convert {format} files into XML as a staging step for further processing in the flow, or to convert XML to a {format} file after the XML has been manipulated. Both of these operations can be accomplished with the {format} connector.</p>

      <p>For details on converting {format} into XML, see the <a href={`#converting-${lower}-to-xml`}>Converting {format} to XML</a> section. For details on converting XML into {format}, see the <a href={`#converting-xml-to-${lower}`}>Converting XML to {format}</a> section.</p>
    </>;
};

export const NameDescription = ({extraRows}) => <table>
    <thead>
      <tr>
        <th>Setting</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><strong>Connector Id</strong></td>
        <td>The static, unique identifier for the connector.</td>
      </tr>
      <tr>
        <td><strong>Connector Type</strong></td>
        <td>Displays the connector name and a description of what it does.</td>
      </tr>
      <tr>
        <td><strong>Connector Description</strong></td>
        <td>An optional field to provide a free-form description of the connector and its role in the flow.</td>
      </tr>
      {extraRows}
    </tbody>
  </table>;

export const SlasTab = ({siteName = "CData Arc"}) => <>
    <p><em>Settings related to configuring Service Level Agreements (SLAs).</em></p>
    <p>
      SLAs enable you to configure the volume you expect connectors in your flow to send or receive, and to set the time frame in which you expect that volume to be met. {siteName} sends emails to warn the user when an SLA is not met, and marks the SLA as <em>At Risk</em>, which means that if the SLA is not met soon, it will be marked as <em>Violated</em>. This gives the user an opportunity to step in and determine the reasons the SLA is not being met, and to take appropriate actions. If the SLA is still not met at the end of the at-risk time period, the SLA is marked as violated, and the user is notified again.
    </p>
    <p>
      To define an SLA, toggle <strong>Expected Volume</strong> on, then click the <strong>Settings</strong> tab.
    </p>
    <img src="/public/images/sla_empty.png" alt="SLA Empty" />
    <ul>
      <li>If your connector has separate send and receive actions, use the radio buttons to specify which direction the SLA pertains to.</li>
      <li>In the <strong>Expect at least</strong> portion of the window:
        <ul>
          <li>Set the minimum number of transactions you expect to be processed (the volume)</li>
          <li>Use the <strong>Every</strong> fields to specify the time frame</li>
          <li>Indicate when the SLA should go into effect. If you choose <strong>Starting on</strong>, complete the date and time fields.</li>
          <li>Check the boxes for the days of the week that you want the SLA to be in effect. Use the dropdown to choose <strong>Everyday</strong> if necessary.</li>
        </ul>
      </li>
      <li>In the <strong>Set status to 'At Risk'</strong> portion of the window, specify when the SLA should be marked as at risk.
        <ul>
          <li>By default, notifications are not sent until an SLA is in violation. To change that, check <strong>Send an 'At Risk' notification</strong>.</li>
        </ul>
      </li>
    </ul>
    <p>
      The following example shows an SLA configured for a connector that expects to receive 1000 files every day Monday-Friday. An at-risk notification is sent 1 hour before the end of the time period if the 1000 files have not been received.
    </p>
    <img src="/public/images/sla_defined.png" alt="SLA Configuration Example" />
    <Note>
      You can turn off SLA alerts if necessary. This can be useful during maintenance windows. Click <strong>Settings</strong> on the navbar, then navigate to <strong>Alerts &gt; General Alerts</strong>. Click the tablet and pencil icon to edit, and uncheck the <strong>SLA Alerts</strong> setting.
    </Note>
  </>;

export const AlertsTab = ({siteNameShort = "Arc"}) => <>
    <p><em>Settings related to configuring alerts.</em></p>
    <p>
      Before you can execute Service Level Agreements (SLAs), you need to set up email alerts for notifications. By default, {siteNameShort} uses the global settings on the <a href="/26.3/cloud/en/getting-started/administration/settings/alerts">Alerts</a> tab. To use other settings for this connector, toggle <strong>Override global setting</strong> on.
    </p>
    <p>
      By default, error alerts are enabled, which means that emails are sent whenever there is an error. To turn them off, uncheck the <strong>Enable</strong> checkbox.
    </p>
    <p>
      Enter a <strong>Subject</strong> (mandatory). Check <strong>Allow {siteNameShort}Script in Subject</strong> to use {siteNameShort}Script in the <strong>Subject</strong> field. When you select this, the <strong>{siteNameShort}Script Editor</strong> button appears (<img src="/public/images/rest_arcscript_editor.png" alt="arcscript editor button" style={{
  display: 'inline',
  verticalAlign: 'middle',
  margin: 0
}} />).
    </p>
    <p>
      Optionally, enter a comma-separated list of <strong>Recipient</strong> emails.
    </p>
  </>;

export const MiscConnector = () => <>
    <p><em>Miscellaneous settings are for specific use cases.</em></p>
    <table>
      <thead>
        <tr>
          <th>Setting</th>
          <th>Description</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td><strong>Other Settings</strong></td>
          <td>Enables you to configure hidden connector settings in a semicolon-separated list (for example, <code>setting1=value1;setting2=value2</code>). Normal connector use cases and functionality should not require the use of these settings.</td>
        </tr>
      </tbody>
    </table>
  </>;

export const Logging = () => <>
    <p><em>Settings that govern the creation and storage of logs.</em></p>
    <table>
      <thead>
        <tr>
          <th>Setting</th>
          <th>Description</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td><strong>Log Level</strong></td>
          <td>The verbosity of logs generated by the connector. When you request support, set this to <strong>Debug</strong>.</td>
        </tr>
        <tr>
          <td><strong>Log Subfolder Scheme</strong></td>
          <td>Instructs the connector to group files in the Logs folder according to the selected interval. The <strong>Weekly</strong> option (which is the default) instructs the connector to create a new subfolder each week and store all logs for the week in that folder. Leaving this setting blank tells the connector to save all logs directly in the Logs folder. For connectors that process many transactions, using subfolders helps keep logs organized and improves performance.</td>
        </tr>
        <tr>
          <td><strong>Log Messages</strong></td>
          <td>Check this to have the log entry for a processed file include a copy of the file itself. If you disable this, you might not be able to download a copy of the file from the <strong>Transactions</strong> tab.</td>
        </tr>
      </tbody>
    </table>
  </>;

export const MacrosExamples = ({extraMacros = []}) => <>
    <p>
      Some macros, such as %Ext% and %ShortDate%, do not require an argument, but others do. All
      macros that take an argument use the following syntax: <code>%Macro:argument%</code>
    </p>

    <p>Here are some examples of the macros that take an argument:</p>

    <ul>
      <li>%Header:headername%: Where <code>headername</code> is the name of a header on a message.</li>
      <li>%Header:mycustomheader% resolves to the value of the <code>mycustomheader</code> header set on the input message.</li>
      <li>%Header:ponum% resolves to the value of the <code>ponum</code> header set on the input message.</li>
      <li>%RegexFilename:pattern%: Where <code>pattern</code> is a regex pattern. For example, <code>%RegexFilename:^([\w][A-Za-z]+)%</code> matches and resolves to the first word in the filename and is case insensitive (<code>test_file.xml</code> resolves to <code>test</code>).</li>
      <li>%Vault:vaultitem%: Where <code>vaultitem</code> is the name of an item in the <a href="/26.3/cloud/en/getting-started/administration/settings/global-settings-vault">vault</a>. For example, <code>%Vault:companyname%</code> resolves to the value of the <code>companyname</code> item stored in the vault.</li>
      <li>%DateFormat:format%: Where <code>format</code> is an accepted date format (see <a href="/26.3/cloud/en/scripting/value-formatters/date-formatters#sample-date-formats">Sample Date Formats</a> for details). For example, <code>%DateFormat:yyyy-MM-dd-HH-mm-ss-fff%</code> resolves to the date and timestamp on the file.</li>
      {extraMacros.filter(item => item.example).map(item => <li key={`ex-${item.name}`}>{item.example}</li>)}
    </ul>

    <p>You can also create more sophisticated macros, as shown in the following examples:</p>

    <ul>
      <li>Combining multiple macros in one filename: <code>%DateFormat:yyyy-MM-dd-HH-mm-ss-fff%%EXT%</code></li>
      <li>Including text outside of the macro: <code>MyFile_%DateFormat:yyyy-MM-dd-HH-mm-ss-fff%</code></li>
      <li>Including text within the macro: <code>%DateFormat:'DateProcessed-'yyyy-MM-dd_'TimeProcessed-'HH-mm-ss%</code></li>
    </ul>
  </>;

export const MacrosTable = ({siteName = "CData Arc", extraMacros = []}) => <>
    <p>
      Using macros in file naming strategies can enhance organizational efficiency and contextual
      understanding of data. By incorporating macros into filenames, you can dynamically include
      relevant information such as identifiers, timestamps, and header information, providing
      valuable context to each file.
    </p>

    <p>{siteName} supports these macros, which all use the following syntax: <code>%Macro%</code>.</p>

    <table>
      <thead>
        <tr><th>Macro</th><th>Description</th></tr>
      </thead>
      <tbody>
        <tr><td>ConnectorID</td><td>Evaluates to the ConnectorID of the connector.</td></tr>
        <tr><td>ConnectorName</td><td>Evaluates to the name of the connector. Enables you to include the connection name in file names or paths: for example, to tag backup files by which database connection produced them.</td></tr>
        <tr><td>Ext</td><td>Evaluates to the file extension of the file currently being processed by the connector.</td></tr>
        <tr><td>Filename</td><td>Evaluates to the filename (extension included) of the file currently being processed by the connector.</td></tr>
        <tr><td>FilenameNoExt</td><td>Evaluates to the filename (without the extension) of the file currently being processed by the connector.</td></tr>
        <tr><td>MessageId</td><td>Evaluates to the MessageId of the message being output by the connector.</td></tr>
        <tr><td>RegexFilename:<em>pattern</em></td><td>Applies a RegEx pattern to the filename of the file currently being processed by the connector.</td></tr>
        <tr><td>Header:<em>headername</em></td><td>Evaluates to the value of a targeted header (<code>headername</code>) on the current message being processed by the connector.</td></tr>
        <tr><td>LongDate</td><td>Evaluates to the current datetime of the system in long-handed format (for example, Wednesday, January 24, 2024).</td></tr>
        <tr><td>ShortDate</td><td>Evaluates to the current datetime of the system in a yyyy-MM-dd format (for example, 2024-01-24).</td></tr>
        <tr><td>DateFormat:<em>format</em></td><td>Evaluates to the current datetime of the system in the specified format (<code>format</code>). See <a href="/26.3/cloud/en/scripting/value-formatters/date-formatters#date-formats-with-literal-characters">Sample Date Formats</a> for the available datetime formats.</td></tr>
        <tr><td>Vault:<em>vaultitem</em></td><td>Evaluates to the value of the specified vault item.</td></tr>
        {extraMacros.map(item => <tr key={item.name}>
            <td>{item.name}</td>
            <td>{item.description}</td>
          </tr>)}
      </tbody>
    </table>
  </>;

export const Performance = () => <>
    <p><em>Settings related to the allocation of resources to the connector.</em></p>
    <table>
      <thead>
        <tr>
          <th>Setting</th>
          <th>Description</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td><strong>Max Workers</strong></td>
          <td>The maximum number of worker threads consumed from the threadpool to process files on this connector. If set, this overrides the default setting on the <a href="/26.3/cloud/en/getting-started/administration/settings/performance-settings">Performance Settings</a> portion of the <a href="/26.3/cloud/en/getting-started/administration/settings/advanced-settings">Advanced Settings</a> page.</td>
        </tr>
        <tr>
          <td><strong>Max Files</strong></td>
          <td>The maximum number of files sent by each thread assigned to the connector. If set, this overrides the default setting on the <a href="/26.3/cloud/en/getting-started/administration/settings/performance-settings">Performance Settings</a> portion of the <a href="/26.3/cloud/en/getting-started/administration/settings/advanced-settings">Advanced Settings</a> page.</td>
        </tr>
      </tbody>
    </table>
  </>;

The CSV connector converts comma-separated values (CSV) files into XML and generates CSV files from XML.

## Key Capabilities

* Bidirectional CSV/XML conversion with configurable delimiters and encoding
* Header detection and custom column mapping capabilities
* Support for various character encodings and special character handling

## Overview

<DelimitedOverview format="CSV" />

## Connector Configuration

This section contains all of the configurable connector properties.

### Settings Tab

#### Configuration

*Settings related to the connector Id and description.*

<NameDescription />

#### Connector Settings

*Settings related to the core operation of the connector.*

<DelimitedConnectorSettings format="CSV" />

#### Other Settings

*Settings not included in the previous categories.*

<DelimitedOtherSettings />

### Sample Files Tab

<DelimitedSampleFiles />

### Advanced Tab

<DelimitedProcessingDelay />

#### Logging

<Logging />

#### Miscellaneous

<MiscConnector />

### Automation Tab

#### Automation Settings

<DelimitedAutomationSettings />

#### Performance

<Performance />

### Alerts Tab

<AlertsTab />

### SLAs Tab

<SlasTab />

## Converting CSV to XML

When a {format_0} file is transformed into XML, the resulting XML has the following structure:

```xml theme={null}
<Items>
  <Record>
    <field_0></field_0>
    <field_1></field_1>
    <field_2></field_2>
  </Record>
</Items>
```

Each row (record) in the original file becomes a child of the root element `Items`. The name of all record elements is determined by the **Record Name** option set in [Connector Settings](#connector-settings). Each record element then has child elements corresponding to the values in each row of the input file.

Some {format_0} files include a line of header information that provides context to the values in the file. When the **First line is header information** setting is enabled, this header line is parsed, and the parsed headers are used as the element names for the value elements (the children of the record elements). Otherwise, the value elements are given generic names such as `field_0`, `field_1`, and so on.

## Converting XML to CSV

To convert XML to a {format_1} file, the input XML must have a 'flat' structure. This means that, disregarding the `Items` root element, the depth of the XML structure is two. For example:

```xml theme={null}
<Items>
  <film>
    <title>Citizen Kane</title>
    <year>1941</year>
    <runtime>119</runtime>
  </film>
  <film>
    <title>Sharknado</title>
    <year>2013</year>
    <runtime>86</runtime>
  </film>
</Items>
```

The XML is interpreted as follows:

* Children of the root element are treated as records (rows) in the resulting file
* Children of each record element are treated as the values in each row

If the **First line is header information** option is enabled, a header row is inserted into the resulting {format_1} file with the names of each value element to provide context to the values. In the example above, this header row would consist of `title`, `year`, and `runtime`.

## Print View

<DelimitedPrintView format="CSV" />

## CSV Transformation: Using the XML Map Connector

<DelimitedXmlMapTransformation format="CSV" />

## CSV Operations

In addition to the [Operations](/26.3/cloud/en/scripting/operations/operations) provided with Arc, connectors can provide operations that extend functionality into ArcScript.

These connector operations can be called just like any other ArcScript operation, except for two details:

1. They must be called through the `connector.rsc` endpoint.
2. They must include an auth token.

For example, calling a connector operation using both of these rules might look something like this:

```xml theme={null}
<arc:set attr="in.myInput" value="myvalue" />
<arc:call op="connector.rsc/opName" authtoken="admin:1j9P8v8b9K0x6g5R5t7k" in="in" out="out">
  <!-- handle output from the op here -->
</arc:call>
```

Operations specific to the functionality of the CSV connector are listed below.

### csvListRecords

Loops over every record in a specified CSV file or string. See [Functions](../scripting/value-formatters/function-formatters) for more details.

#### Required Parameters

* **file**: The path to the CSV file.

#### Optional Parameters

* **data**: If the CSV data exists as a string rather than stored in a CSV file, use this parameter instead of **file**.
* **columns**: The comma-separated list of columns to include in the output (if unspecified, all columns are included).
* **requireheader**: By default, the first row of data is interpreted as column headers; pass *false* to this parameter to use generic column names (for example, c1, c2, c3).

#### Output

Any script in a *csvListRecords* operation executes multiple times: once for each record/row in the input CSV file/data. Within the operation, individual CSV values are accessible using the *csv* formatter. This formatter takes a column name as a parameter, and outputs the value in that column for the current record.

For example, imagine the CSV input data contains a set of items purchased in an order, and the name of the item is held in the `ItemName` column. The following script generates XML containing each `ItemName` value in an `Item` element:

```xml theme={null}
<ItemList>
  <arc:call op="csvListRecords?file=myFile.csv">
    <Item>[csv('ItemName')]</Item>
  </arc:call>
</ItemList>
```

## Macros

<MacrosTable />

### Examples

<MacrosExamples />
