# Shared Actions

Shared actions in Astera allow sharing an item or an action at multiple places. The item that needs to be used repeatedly can be extracted into a *Shared Action*, which can then be used wherever needed. Moreover, any changes or updates that need to be made to an item can be made only in the *Shared Action*, and all occurrences of the *Shared Action* item will automatically accommodate all the changes.

### **How to Create and Use Shared Actions**

There are two methods to create and use shared actions in Astera.

1. Creating a new *Shared Action* in the project.
2. Creating and saving an item from a flow as a *Shared Action.*

Let’s see how both methods work through the following use cases.

### **Use Cases**

#### **Use Case 1: Database Connection as a Shared Action**

A database connection needs to be used over and over again in a project. Instead of creating a new connection every time, we can create a *Shared Action* for the database connection and use it wherever it is needed within the project.

**Creating a Database Connection as a Shared Action**

Right-click your project in the *Project Explorer* and select *Add New Item*.

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FR8lWAD2ztZjBBI4O7Jmg%2F01-add-new-project.png?alt=media\&token=1423ef91-6946-42e8-b9c3-c8d89fa5eb98)

An *Add New Item* window will open. Select a *SharedAction* item from the window. Rename your *SharedAction* item and click *Add*.

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FyV3Tb1SUgmWJqxCkgJ9P%2F02-add-new-item-window.png?alt=media\&token=5a88791b-257f-4bf0-a5bf-c07c0d867b23)

This will add a *Shared Action* to your project. A *Shared Action* file has a .*Sact* extension.

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FmpGcKDLakAXab9qMFgub%2F03-shared-action-file.png?alt=media\&token=fb3adfb4-f23a-492a-836f-882fbd5348c2)

Double-click the newly created *Shared Action* to open it in the designer. Drag and drop a *Database Connection* object from *Toolbox > Resources* onto the designer.

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FNXj3oiak7mKQqHeRiWDm%2F04-db-connection-object.png?alt=media\&token=e19d830b-3599-4f06-8800-0505c70678d9)

Double-click the *DbConnection* Object. A *DbConnection* properties window will open. Add database connection details and click *OK*.

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FAzgzLWxnideX5BAxrVpE%2F05-db-connection-configuration.png?alt=media\&token=0388fad6-8d70-40b3-af1e-9781522ce67b)

The database connection is now configured as a *Shared Action*. Press Ctrl + S or go to *File > Save* to save the *Shared Action*.

You can now use your *Shared Action* in any flow within the project.

**Using Database Connection Shared Action in a Dataflow**

Open a dataflow that uses a [*DatabaseSource*](https://documentation.astera.com/astera-data-stack-v10/dataflows/sources/database-table-source) object within your project. Open the *DatabaseSource* properties window by double-clicking on it.

Select the *Use Shared Connection* option. The dropdown will show a list of all the database connections saved as a *Shared Action*.

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FXjPdbvHzzubSmyIa1TrL%2F06-db-shared-connection.png?alt=media\&token=dc0d008f-7630-4345-b085-af1921bcfe9c)

Similarly, you can use the *SharedAction* in all dataflows, workflows or subflows within the project. If something changes in your database connection, you will only have to update it in the *Shared Action* and all the flows using it will automatically accommodate all the changes.

{% hint style="info" %}
**Note:** The Database Connection shared action can be used with any other object that supports the usage of shared connections. Some examples of these objects include the [*SQL Statement Lookup*](https://documentation.astera.com/astera-data-stack-v10/dataflows/transformations/sql-statement-lookup) and [*SQL Query Source*](https://documentation.astera.com/astera-data-stack-v10/dataflows/sources/sql-query-source) objects in a dataflow and the [*Run SQL Script*](https://documentation.astera.com/astera-data-stack-v10/workflows/run-sql-script) and [*Run SQL File*](https://documentation.astera.com/astera-data-stack-v10/workflows/run-sql-file) objects in a workflow.
{% endhint %}

#### **Use Case 2: Transformation Object as Shared Action**

The following dataflow extracts data from a database table using a [*DatabaseSource*](https://documentation.astera.com/astera-data-stack-v10/dataflows/sources/database-table-source) object and converts the unit price of an item from USD to PKR using an expression. It then writes the data to an [*Excel Destination*](https://documentation.astera.com/astera-data-stack-v10/dataflows/destinations/excel-workbook-destination).

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FVhl0ED4LDUb49PKLDowB%2F07-dataflow-shared-action.png?alt=media\&token=e7c03eed-7510-4aeb-acd2-040df7f878b4)

To reuse this [*Expression*](https://documentation.astera.com/astera-data-stack-v10/dataflows/transformations/expression-transformation) in various flows within the project, we can extract the *Expression* into a *Shared Action* and use it wherever it is needed.

**Saving an Expression as a Shared Action**

Right-click the *Expression* object and select *Save as Shared Action* option.

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FlBZQJYACTyxy1bbzy44J%2F08-save-as-shared-action.png?alt=media\&token=cd29328c-7bb8-4ab1-98b3-8e2176781c18)

Select a destination where you want to save the *Shared Action* file and provide a file name. Click *Save*.

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2F3Ah0ygr8aZWe7oq5hObX%2F09-sa-save-window.png?alt=media\&token=6821637a-d5a2-4715-a31e-ae09262e6a3e)

The *Shared Action* file has been saved. To add it to the project, right-click on your project in the *Project Explorer* and select *Add Existing Items*.

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FNnVwP3Ey12CM2H62CNNn%2F10-project-add-existing-item.png?alt=media\&token=3955f35f-af5e-4a4f-82db-25409343b5db)

Select the *Shared Action* file you created from the file explorer window that appears. Click *Open*.

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2F8gTj41M3UWFUpN7BcaH4%2F11-add-sact-file.png?alt=media\&token=7e6d01f3-6509-4264-b154-b5bc6fa4025b)

This will add the *Shared Action* file to your project.

{% hint style="info" %}
**Note:** To use a *Shared Action*, the *Shared Action* file must be within the same project where it is needed.
{% endhint %}

**Using a Shared Action**

To use the [*Expression*](https://documentation.astera.com/astera-data-stack-v10/dataflows/transformations/expression-transformation) saved as a Shared Action in a flow, drag and drop the *Shared Action* (.sact file) from the *Project Explorer* to the designer.

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FGxb1tCQpKDJhXSKcCEXd%2F12-drag-and-drop-shared-action.png?alt=media\&token=26380f91-3ef0-4973-8bba-8c39e5ee86fb)

Notice that the Shared Action object title is italicized.

We can now use this *Shared Action Expression* in any other workflow, dataflow or subflow within the same project by dragging and dropping it wherever it is needed.

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FK2pITh6BiaIgimc1oIB7%2F13-dataflow2-shared-action.png?alt=media\&token=293c32e6-6306-464c-b4cb-7159cc2ee29d)

Now, if we want to make a change to the [*Expression*](https://documentation.astera.com/astera-data-stack-v10/dataflows/transformations/expression-transformation) (let’s say the currency exchange rate changes), we will only have to update the *Expression* in the *Shared Action* and all the flows using it will automatically accommodate all the changes.

#### **Changing a Shared Action back to Local Object**

To change a *Shared Action* back to a local object, right-click the *Shared Action* object and select *Change Shared Action to Local* option.

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2F22x1gd9gTGM52afL4uBk%2F14-shared-action-to-local-object.png?alt=media\&token=89b3cb2c-38c2-4ed7-b215-78b008466606)

#### **Editing a Shared Action**

To edit a *Shared Action*, right-click the *Shared Action* object and select the *Edit Shared Action File* option. This will redirect you to the *Shared Action* file where you can make the desired changes.

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FVOuMoqU60gL14lYJyEIs%2F15-edit-shared-action.png?alt=media\&token=6eeebb89-91ae-4407-997e-05fab1c5b146)

#### **Editing Shared Action File Path**

To edit the *Shared Action* file path, double-click the *Shared Action* object. You can select a new path by clicking on the File (📂) icon under the *Shared Action Location* section of *Shared Action Properties* window.

![](https://3083465318-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsR50Wa7EwZGlmPSAMkkf%2Fuploads%2FWKYRmbp1pIg4ZNnS1Grj%2F16-change-shared-action-filepath.png?alt=media\&token=d0a9e7e3-9de7-4824-9e54-88fe7457f826)

This concludes our discussion on how to create and use shared actions in an Astera project.
