> For the complete documentation index, see [llms.txt](https://docs.fabricplan.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.fabricplan.com/powertable-sheets/how-tos/automation/create-a-sample-automation.md).

# Create a sample automation

This article extends the [Configure automation workflows](/powertable-sheets/how-tos/automation/configure-automation-workflows.md) how-to guide by showing how to create an automation workflow by using a sample customer order processing scenario.

{% hint style="info" %}

### Note

To learn more about the concept of automation and how to set up the different triggers and actions, see [Automation](/powertable-sheets/concepts/automation.md) and [Configure automation workflows](/powertable-sheets/how-tos/automation/configure-automation-workflows.md).
{% endhint %}

### Sample scenario

For this example, consider the following tables in PowerTable:

1. An **Order Requests** table to store customer order requests submitted through a form.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2F4D2uBZRholb0FCwCLb4M%2Fimage.png?alt=media&amp;token=eec2cbdf-69a3-424b-b63e-e19ef9954df1" alt=""><figcaption></figcaption></figure>

* An **Orders** table to store processed orders.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FJCyl2Wduscoyh4Thw8f4%2Fimage.png?alt=media&amp;token=df302224-ebd4-4a41-a5cb-cba1a3974142" alt=""><figcaption></figcaption></figure>

* An **Inventory** table that contains product information and available stock quantities.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FvGIeFAd5jJOpxlGCy6ef%2Fimage.png?alt=media&amp;token=2f407893-e596-4f8a-9a4a-367b922745e4" alt=""><figcaption></figcaption></figure>

* A [form](/powertable-sheets/how-tos/generate-forms.md) that stores customer order requests in the **Order Requests** table.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FWl5AZWx75bUGmlx3FBqq%2Fscreenshot_03.png?alt=media&amp;token=6f873f40-10af-4b65-8c43-ad650dec91c2" alt="" width="563"><figcaption></figcaption></figure>

### Workflow overview

When a customer submits an order request through the form, the workflow verifies inventory for the requested product and then performs the appropriate actions based on stock availability.

The workflow retrieves the product details from the **Inventory** table, checks whether sufficient stock is available, and either creates an order and updates inventory or marks the product for restocking.

The workflow performs the following tasks:

1. A customer submits an order request through the form.
2. The **When a form is submitted** trigger starts the workflow.
3. The **Find Record(s)** action retrieves the requested product details from the **Inventory** table.
4. The workflow compares the requested quantity with the available stock quantity.
5. If sufficient stock is available, the workflow:
   * Creates an order record in the **Orders** table.
   * Sets the order status to **Processing**.
   * Updates the inventory by subtracting the requested quantity from the available stock.
6. Otherwise, the workflow updates the **Restock** status in the **Inventory** table to indicate that additional stock is required.

### Create the workflow and add trigger

1. Open the **Order Requests** table.
2. Create a new automation workflow. To learn more about creating an automation, see [Create an automation flow](/powertable-sheets/how-tos/automation/configure-automation-workflows.md#create-an-automation-flow).

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2F16TwIgqyI8bKie3baBeW%2Fimage.png?alt=media&amp;token=5100c563-c554-4cc1-bea5-acaa5d4a3439" alt=""><figcaption></figcaption></figure>

3. Select **When a form is submitted** as the trigger.
4. [Configure the trigger](/powertable-sheets/how-tos/automation/configure-automation-workflows.md#add-trigger) to run only when the required customer details are present in the **Properties** pane. The trigger starts only when the

* *Customer Phone*, *Product Name* and *Quantity* **are not empty**.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2F8XfqDUkWr4YEd9SuhGJs%2Fscreenshot_04.png?alt=media&amp;token=fd442f84-2028-4a32-9046-a737ccb4c88c" alt=""><figcaption></figcaption></figure>

### Retrieve the product details

1. Select **Add Action** > **Find Record(s)**.
2. Select the schema. In **Table**, select **Inventory**.
3. Select **Single Record** to fetch the single matching product record.
4. [Configure the action](/powertable-sheets/how-tos/automation/configure-automation-workflows.md#find-record-s) to find the product that matches the product requested in the submitted form. Use *ProductName* to find the matching product since the form has only the product name.
5. Return the **Product Key**, **Product Name**, and **Stock Quantity** fields by selecting them in **Select columns**.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FvxKk9VgwjqU8e2WmEGU0%2Fscreenshot_05.png?alt=media&amp;token=42f138ce-0453-484e-84ab-0f458652db6a" alt=""><figcaption></figcaption></figure>

The workflow uses the retrieved product details to validate stock inventory and populate the order record.

### Add a condition

1. Add a **Conditional Group**.
2. Configure the **If** condition to check if the requested quantity is lesser than the available stock quantity.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FvGIhIsjKAu6NNOLFndn0%2Fscreenshot_06.png?alt=media&amp;token=6af905b9-cbf0-4529-ac7d-9e696802a088" alt=""><figcaption></figcaption></figure>

### Configure the If branch

If sufficient stock is available, create a record in the **orders** table.

* Add a [**Create Record**](/powertable-sheets/how-tos/automation/configure-automation-workflows.md#create-record) action.
* Select the schema and select ***Orders1*** in **Table**.
* Select **Add Field** to add the fields for the record.
* For field values, select **+** and map the customer
* details from the **Order Requests** table, sourced from the form.
* For product-related fields, map the product details from the **Find Record(s)** action. For example, retrieve the *Product Key* from **Inventory** table fetched by using **Find Record(s)**.
* Set the **Status** field to *Processing*.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FqbTNVrFDRxvaDNpyaKZ0%2Fscreenshot_07.png?alt=media&amp;token=59bc48a8-92af-44d9-9d80-3812a77dfd8e" alt=""><figcaption></figcaption></figure>

Also, update the stock in inventory.

* Add an [**Update Record**](/powertable-sheets/how-tos/automation/configure-automation-workflows.md#update-record) action.
* Select the schema and select **Inventory** table.
* Select **Single Update** to update a single record.
* Use the *ProductKey* in **Rules** to identify the corresponding product.
* **Select** **Replace Value** and **Subtract**. Then, select the *Stock* and *Quantity* fields to update the inventory record by subtracting the requested quantity from the available stock.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FekuingpZ0eVTdf5Gr5QE%2Fscreenshot_08.png?alt=media&amp;token=e574db67-1c5c-4a08-a236-986d455e1b86" alt=""><figcaption></figcaption></figure>

### Add Otherwise branch

1. Select **Add Condition** to add another condition branch.
2. Select **If no other condition are met** to make it a final branch.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FRQI2lIgS2TePdtA5Dzir%2Fscreenshot_09.png?alt=media&amp;token=2b8d9762-1c6c-41ff-a062-126d8a70d389" alt=""><figcaption></figcaption></figure>

### Configure the Otherwise branch

If sufficient stock isn't available, update the restock field in the **Inventory** table to *Yes.*

* Add an **Update Record** action.
* Select the schema and select **Inventory** table.
* Select **Single Update** to update a single record.
* Use the *ProductKey* in **Rules** to identify the corresponding product.
* Update the corresponding inventory record.
* Set the **Restock** field to **Yes** and update the last updated date.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FvsnjV0MNSoOvJzM1BIxT%2Fscreenshot_10.png?alt=media&amp;token=3bfad74a-73a8-4f24-85eb-41475c740d51" alt=""><figcaption></figcaption></figure>

The flow is complete.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FJTC1IuPboH6a0ksIiuUm%2Fimage.png?alt=media&amp;token=f5dba2ad-6498-4aad-af0c-b7df0b36e8b5" alt="" width="563"><figcaption></figcaption></figure>

Consider a user submits the form as shown in the following image.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FvJWOULyN2e9PTNOSeHtW%2Fscreenshot_11.png?alt=media&amp;token=3a727bcb-b2f1-42bf-822c-82f899678fab" alt="" width="563"><figcaption></figcaption></figure>

The orders table is updated. The stock inventory is also updated from 60 to 40 as seen in the *Stock* reference column.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FEGxt64kZAEdH9ovGXcgy%2Fscreenshot_12.png?alt=media&amp;token=40e6ef91-30f2-4f6b-9114-1a2c91d8ed61" alt=""><figcaption></figcaption></figure>


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.fabricplan.com/powertable-sheets/how-tos/automation/create-a-sample-automation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
