Writing Data
Last updated
Last updated
Your projects will be writing data to files, databases, SAAS, and other targets. appRules includes activities for writing data in a variety of data sources.
To write data to an appRules target, you will need to initialize the Target of the data, select the connector to use and define other properties using the InitializeTarget activity.
For example, to write data to Microsoft SQL Server, drag and drop the InitializeTarget activity from the SQL Server toolbox on to the designer and configure the properties as follows:
Property
Description
DataSource
Select the datasource and entity (table) to be used in this Target for inserting/updating/deleting data records.
You can specify whether to cache the records in a preloaded table (set a lookuppreloaded source in the project and select it here), optionally select an insert/update activity (set in the project) and execute a customfunction or a child workflow for each batch completion.
Before writing records in the target data source, the values of the data fields of the active record must be set.
The table below shows the activities that can be used to set the data field values of the active record:
Activity
Module
Notes
MapAndSetFields
Supported in every modules such as SQL Server, Dynamics CRM etc.
Any number of MapAndSetFields activities can be used to set data field values. Field mapping was described in detail in the previous chapter.
SetValues
Base Module
Any number of SetValues activities can be used to set data field values
ClearRecord
Record Module
Clears the active record from the selected Datasource
CopyRecord
Record Module
Copies field values from another Source or Target record to the active record
TransformValues
Base Module
Transforms data field values from the related target record
MapAndSaveRecords
Base Module
Use the MapAndSaveRecords activity for bulk imports. This activity takes a source and a target and automatically reads all the records into the target.
Once the data field values in the active record have been set, you can save the new record in the target by using the SaveRecord activity.
For example, to insert record into SQL Server, drag and drop the SaveRecord activity from the SQL Server toolbox activities on to the designer.
Select the Target for inserting the record. All the field values that have been set or mapped to the current record for the selected target will be added to the data source.
Click on the Option field and Select Insert in the Configure Record Save Option Window
To retrieve the key of the newly created record, tick the Retrieve New Record Key box. The key value will be made part of the target record after inserting the record (to be used for example to generate a related record in the following processed activities).
You can also define optional properties for including more field values to save and also for logging detailed errors associated with adding the new record. To define optional details, click the Optional properties button. The following window will be displayed:
Enter the property values as follows:
Property
Description
DataFieldValues
Click to Collection property button to define the additional fields and values to be saved in the data source.
TargetClearRecord
Check this box to clear the target record before setting the values using DataFieldValues.
Existing records can be updated using the SaveRecord activity, drag and drop the SaveRecord activity from the related connector activities tool box into the designer.
Select the Target for updating the record (see Inserting Records). All the field values that have been set or mapped to the current record for the selected target will be updated to the data source.
Click on the Option field and Select Update in the Configure Record Save Option Window
You must also select whether to update the record using a PrimaryKey or a CompositeKey. Click on the Unique Key or Composite Key value to do it.
All the field values that have been set or mapped to the current record for the selected target will be updated in the data source.
You can also define optional properties for including more field values to update. click the optional properties button. The following window will be displayed:
Enter the property values as follows:
Property
Description
DataFieldValues
Click to Collection property button to define the additional fields and values to be saved in the data source.
TargetClearRecord
Check this box to clear the target record before setting the values using DataFieldValues.
The SaveRecord has an option to combine the Insert and Update
At run time, if the record exists, it is updated. If the record does not exist at run time, it is inserted into the target.
Select the Target for upserting the record and Upsert in the Configure Record Save Option
Specify the Insert/Update and the Lookup Settings (value to be tested to check if the record exists or not)
Optional Properties are defined the same way as Insert/Update above
The DeleteRecord activity is used for deleting records from a target.drag and drop the DeleteRecord activity on to the designer. To delete a record, the record key is required.
At run time, if the record exists, it is deleted.
Select the Target for updating the record. You must also select whether to delete the record using a PrimaryKey or a CompositeKey (RecordKeyType). If you use a composite key, define the fields/values used in the CompositeKey collection.
No Optional properties available for this activity