> For the complete documentation index, see [llms.txt](https://docs.appstrategy.com/apprules-r-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.appstrategy.com/apprules-r-documentation/platform/platform-features/base-activities/base-activities-3.md). Agents can also search and read this documentation through its [MCP server](https://docs.appstrategy.com/apprules-r-documentation/~gitbook/mcp).

# Base Data Activities

### Base Data Module

The Base Data activities module provides activities for generalized data access in your project. They can be applied to all data sources defined in the current project — database and application connections (Dynamics 365, Salesforce, SQL Server, MySQL, Oracle, etc.) as well as delimited and fixed-length files.

<div data-with-frame="true"><figure><img src="https://1923141441-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFjmFrZ8sef1J7qkr6H%2Fuploads%2FD6ZnbykcvkYD8k1Krdb8%2Fimage.png?alt=media&amp;token=6a612fc1-a216-4359-9bec-7eea5bbfe456" alt=""><figcaption></figcaption></figure></div>

#### Activities

The table below lists the activities in the Base Data Activities module.

| Activity                | Description                                                                                                                                                                                                             |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ClearRecord             | Clears the field values of the current record of a selected source or target **in memory**. It does not delete the record from the data source.                                                                         |
| CloseSource             | Closes the specified source connection.                                                                                                                                                                                 |
| CloseTarget             | Closes the specified target connection.                                                                                                                                                                                 |
| CopyRecord              | Copies the current record from a source or target to another source or target **in memory**. All fields or a selected list of fields can be copied. The record is not saved to the data source.                         |
| DeleteRecord            | Deletes the specified target record, identified by its unique key or a composite key.                                                                                                                                   |
| ExecuteSQLScript        | Executes a SQL script file on a data source (Dynamics 365, Salesforce, MySQL, Oracle, etc.). Statements are separated by `GO` lines.                                                                                    |
| ExecuteStatements       | Executes one or more custom SQL statements on a data source.                                                                                                                                                            |
| ExecuteStoredProcedure  | Executes a stored procedure, with optional parameters, on a target connection.                                                                                                                                          |
| GetNextRecord           | Loads the next record from the specified source (an InitializeSource, InitializeSourceFile or InitializeSourceList returning multiple records).                                                                         |
| InitializeSource        | Initializes a connection to a data source for reading data records at run time, using a configured query, a custom SQL query or a stored procedure. Multiple InitializeSource activities can be included in a workflow. |
| InitializeSourceFile    | Initializes a source for reading data records from a **delimited** (e.g. CSV) or **fixed-length** file.                                                                                                                 |
| InitializeSourceList    | Initializes a source for reading records from a list. The list can be defined ad hoc (entries can be imported from a CSV file), from custom values, from a delimited string, or from picklist values.                   |
| InitializeTarget        | Initializes a connection to a data source table/entity for saving output records (Insert/Update/Delete), with normal or bulk loading, audit logs and error thresholds.                                                  |
| InitializeTargetFile    | Initializes a target for writing data records to a **delimited** (e.g. CSV) or **fixed-length** file.                                                                                                                   |
| LookupRecord            | Loads a specific record from a data source, a preloaded record list, a list or a picklist (e.g. loads the company record from a company table based on the contact's CompanyId field).                                  |
| MapAndSaveRecords       | Maps values to the specified data fields of a target and saves the records.                                                                                                                                             |
| MapRecordFields         | Maps values to the specified data fields of a target from multiple sources (records, variables, transformed fields, etc.) without saving.                                                                               |
| PerformRecordListAction | Performs an action on a preloaded list of records: add, remove, clear, copy, count, restart, set values or save.                                                                                                        |
| SaveRecord              | Saves the current target record (Insert, Update, Upsert, Skipsert or SyncUpsert) to a data source, or writes it to a delimited or fixed-length file.                                                                    |

#### Key Properties

**ClearRecord**

| Property | Description                                                                                                  |
| -------- | ------------------------------------------------------------------------------------------------------------ |
| Record   | The source or target whose current record is cleared. *All* can be selected to clear every record in memory. |

**CloseSource / CloseTarget**

| Property        | Description                               |
| --------------- | ----------------------------------------- |
| Source / Target | The source or target connection to close. |

Close a source once you have finished reading from it, so the connection is released and data source statistics are recorded. When a target uses bulk loading, the last batch of records is written when the target is closed.

**CopyRecord**

| Property          | Description                                                                               |
| ----------------- | ----------------------------------------------------------------------------------------- |
| CopyFrom          | The source or target of the record to be copied.                                          |
| CopyTo            | The source or target the record is copied to. Must be different from CopyFrom.            |
| ClearCopyToRecord | Whether to clear the existing fields of the CopyTo record before copying (default: True). |
| CopyAllFields     | Whether to copy all data fields (default: True).                                          |
| DataFields        | The data fields to copy when CopyAllFields is False.                                      |

**DeleteRecord**

| Property | Description                                                                                                                                                                                                |
| -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Target   | The target connection of the record to be deleted.                                                                                                                                                         |
| Option   | How the record is identified: **UniqueKey** (default; the record key defaults to the primary key value of the current record) or **CompositeKey** (a set of data fields and values). See **Save Options**. |

**ExecuteSQLScript**

| Property   | Description                                                                                                    |
| ---------- | -------------------------------------------------------------------------------------------------------------- |
| DataSource | The data source the script runs against.                                                                       |
| ScriptFile | The file containing the SQL script. Enter `GO` on a separate line after each statement or batch to execute it. |

If a statement fails, the error is logged and the remaining statements still run. When the project runs interactively and execution results are enabled, a summary of successful and failed statements is displayed.

**ExecuteStatements**

| Property      | Description                                                                |
| ------------- | -------------------------------------------------------------------------- |
| SQLStatements | The SQL statements to execute on the data source, run in the order listed. |

**ExecuteStoredProcedure**

| Property              | Description                                                                                                 |
| --------------------- | ----------------------------------------------------------------------------------------------------------- |
| Target                | The target connection on which the stored procedure runs.                                                   |
| StoredProcedureName   | The name of the stored procedure, selected from the data source.                                            |
| StoredProcedureParams | Optional parameters for the stored procedure. Selecting a different stored procedure resets the parameters. |

**GetNextRecord**

| Property        | Description                                                                                                                   |
| --------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| Source          | The source of the record to be fetched (lookup sources are excluded).                                                         |
| EndOfListAction | The action to perform after fetching the last record of a preloaded list or ad hoc list, e.g. **EndList** or **RestartList**. |

When the last record has been read, the source reader is closed automatically, and the connection is closed unless it is a shared data source connection. Reading stops when the project's maximum number of records is reached.

**InitializeSource**

| Property            | Description                                                                                                                                                                                |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| DataSource          | The data source connection to read from.                                                                                                                                                   |
| QueryType           | **Configuration** (select the entity, filters and columns), **CustomQuery** (enter a SQL query) or **StoredProcedure** (if supported by the data source).                                  |
| SourceRecords       | Opens the dialog for configuring the query according to the QueryType. Filters and columns are optional; when none are set, all records and all columns are read.                          |
| AutoLoadFirstRecord | Whether to automatically load the first record of the result set (default: True).                                                                                                          |
| PreloadAllRecords   | Whether to load all records into memory (default: False). Required by activities that work on preloaded records, such as PerformRecordListAction and LookupRecord with a preloaded record. |

Tips:

* Unless your workflow needs every column, select only the data fields you need to reduce the data loaded and speed up the workflow.
* When AutoLoadFirstRecord is set and the query returns no record, the activity returns an invalid result, which can be used to branch the workflow.

**InitializeSourceFile / InitializeTargetFile**

| Property   | Description                                                                                              |
| ---------- | -------------------------------------------------------------------------------------------------------- |
| FileType   | **DelimitedFile** (default) or **FixedLengthFile**.                                                      |
| Properties | Opens the configuration dialog for the selected file type (file path, delimiter or column layout, etc.). |

**InitializeSourceList**

| Property   | Description                                                                                              |
| ---------- | -------------------------------------------------------------------------------------------------------- |
| ListType   | How the list is built: **Adhoc** (default), **CustomValues**, **DelimitedString** or **PickListValues**. |
| Properties | Opens the configuration dialog for the selected list type.                                               |

The data source, entity, query type and preload settings of a regular source don't apply to lists and are hidden for this activity. Records are read one at a time with GetNextRecord.

Settings for each list type:

| List type       | Settings                                                                                                                                                                                                                                                                                     |
| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Adhoc           | **ListEntries**: the list entries, defined in the list editor. The first field is the unique key. Entries can also be imported from a CSV file, whose header row supplies the field names. **LoadFirstListItem** (default: False).                                                           |
| CustomValues    | **CustomValues**: the values in the list, each with an optional condition (the value is included only when the condition is true). **FieldName**: the name of the list field (default: `RecordField`). **LoadFirstListItem** (default: True).                                                |
| DelimitedString | **DelimitedString**: the string to split into list values. **FieldSeparator**: the separator character (default: Comma). **FieldName**: the name of the list field (default: `RecordField`). **LoadFirstListItem** (default: True). Leading and trailing spaces are trimmed from the values. |
| PickListValues  | **DataSource** and **PickList**: the picklist whose entries form the list. Each record has the fields `Value` and `Description`.                                                                                                                                                             |

**InitializeTarget**

| Property         | Description                                                                          |
| ---------------- | ------------------------------------------------------------------------------------ |
| DataSource       | The data source connection to write to.                                              |
| PrimaryEntity    | The table/entity records are saved to.                                               |
| LoaderAndLogging | Opens the dialog for record loading, error tracking and logging options (see below). |

Options in the LoaderAndLogging dialog:

| Option                               | Description                                                                                                          |
| ------------------------------------ | -------------------------------------------------------------------------------------------------------------------- |
| LoadOption                           | **Normal** (each record is saved when SaveRecord runs) or **BulkLoad** (records are cached and saved in batches).    |
| BulkLoadBatchSize                    | The number of records saved in each batch when bulk loading.                                                         |
| TargetWorkers                        | Optional worker definitions (data source connection, number of threads, condition) for saving batches in parallel.   |
| AuditLogs                            | Optional settings for logging audit records in the audit logs detail table. If not set, no audit records are logged. |
| MaximumAllowedErrorCount             | The maximum number of record errors allowed (0 = no limit).                                                          |
| EndProcessingIfMaxErrorsExceeded     | Whether to stop the job when the maximum error count is exceeded.                                                    |
| SendNotificationsIfMaxErrorsExceeded | Whether to send job notifications when the maximum error count is exceeded.                                          |

A target can also define default data record actions and SQL statements, which run when the target is initialized.

**LookupRecord**

| Property   | Description                                                                                                               |
| ---------- | ------------------------------------------------------------------------------------------------------------------------- |
| Type       | The type of record to look up: **DataSourceRecord** (default), **PreloadedRecord**, **ListRecord** or **PickListRecord**. |
| Properties | Opens the configuration dialog for the selected lookup type (source, filters, etc.).                                      |

**MapAndSaveRecords**

| Property | Description                                                          |
| -------- | -------------------------------------------------------------------- |
| Target   | The target data source whose selected data fields are set and saved. |

**PerformRecordListAction**

| Property   | Description                                                                                                          |
| ---------- | -------------------------------------------------------------------------------------------------------------------- |
| Type       | The action to perform on the list of records (see below).                                                            |
| Properties | Opens the configuration dialog for the selected action. If the Type is changed, the Properties must be reconfigured. |

| Action                | Description                                                                                                                                                                                                |
| --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| AddRecordToList       | Adds a record to the list.                                                                                                                                                                                 |
| ClearRecords          | Clears the records in the list.                                                                                                                                                                            |
| CopyRecords           | Copies records from the list.                                                                                                                                                                              |
| GetRecordCount        | Gets the number of records in the list.                                                                                                                                                                    |
| RemoveRecordsFromList | Removes records from the list.                                                                                                                                                                             |
| RestartList           | Restarts reading the list from the first record.                                                                                                                                                           |
| SaveRecords           | Saves the preloaded records of a source to a target. Settings: **PreloadedRecords** (a source with PreloadAllRecords set), **Target** (must differ from the source) and **Option** (see **Save Options**). |
| SetRecordValues       | Sets field values in the records of the list.                                                                                                                                                              |

**SaveRecord**

| Property   | Description                                                         |
| ---------- | ------------------------------------------------------------------- |
| RecordType | **DataSource** (default), **DelimitedFile** or **FixedLengthFile**. |
| Properties | Opens the configuration dialog for the selected record type.        |

For the **DataSource** record type, the configuration dialog contains:

| Property  | Description                                                                                                |
| --------- | ---------------------------------------------------------------------------------------------------------- |
| Target    | The target connection of the record to be saved. The activity saves the current record held in the target. |
| Operation | The save option and its settings (see **Save Options** below).                                             |

When the target is configured for bulk load, the record is added to the target's cache and written in bulk; otherwise it is saved immediately. Audit log values and record key values defined on the target are applied before the record is saved.

#### Save Options

The Operation dialog of SaveRecord (and the save settings of other activities that write to a target) uses the following record actions:

| Action     | Behavior                                                                                                                           |
| ---------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| Insert     | Always inserts a new record.                                                                                                       |
| Update     | Updates an existing record identified by its unique key or a composite key.                                                        |
| Upsert     | Looks up the record by its key. If no record is found, or the key value is empty, the record is inserted; otherwise it is updated. |
| Skipsert   | Inserts the record only if it does not already exist. If a matching record is found, the record is skipped.                        |
| SyncUpsert | Handled as an Upsert when the record is saved.                                                                                     |
| Delete     | Deletes the record identified by its unique key or a composite key (used by DeleteRecord).                                         |

Additional settings:

| Setting                   | Description                                                                                                                                                              |
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| UpdateUsingKeyType        | How the record is identified for Update, Upsert, Skipsert and Delete: **UniqueKey** (default) or **CompositeKey**.                                                       |
| RecordKey                 | The value of the unique key (UniqueKey mode), and the data field it applies to.                                                                                          |
| CompositeKey              | The data fields and values that together identify the record (CompositeKey mode). Each entry can have its own condition.                                                 |
| SaveOnCondition           | Optional condition. When it is false, the record is skipped.                                                                                                             |
| UpsertOnCondition         | Optional condition for Upsert/Skipsert. When it is false, the record is inserted without looking up an existing match.                                                   |
| RetrieveNewRecordKey      | Whether to retrieve the key of newly inserted records.                                                                                                                   |
| SaveNewRecordKeyInCache   | Whether to save the new record key in cache.                                                                                                                             |
| GeneratesNewPrimaryId     | Whether the primary key is auto-generated by the data source.                                                                                                            |
| AllowsNewPrimaryIdEntry   | Whether a primary key value can be supplied for a new record.                                                                                                            |
| DataFieldInclusionEntries | Optional list of data fields to add to or remove from the record before it is saved. Each entry applies **Unrestricted**, **OnInsert**, **OnUpdate** or **OnCondition**. |

When a record is saved in bulk (bulk load), an Upsert or Skipsert that matches more than one existing record is skipped.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.appstrategy.com/apprules-r-documentation/platform/platform-features/base-activities/base-activities-3.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
