# Automation (Timer)

Automations are most frequently scheduled applications that are triggered by Timers. However, Linx also comes with a number of event-based triggers, like DirectoryWatchers or MessageQueue listeners that can trigger a Linx application.

## Building a Scheduled Automation

1. Open the Linx Designer and click **Create Solution**.
2. Open the **Utilities** plugin in the plugins panel on the right side of the designer, find the **Timer** service (services have a purple **SVC** prefix) and drag it into the **Solution Explorer** in the top left of your Designer.

   <figure><img src="/files/dcbh1vjt4FkxNdRMr6yn" alt=""><figcaption></figcaption></figure>
3. Linx will open the **TimerEvent** in a tab in the central working area. This is where you will create the logic that executes when the Timer service fires.

   <figure><img src="/files/MTC9xmJQWvLxtb9xJ3I2" alt=""><figcaption></figcaption></figure>
4. Select the **Timer** service in the **Solution Explorer** and locate the **Run every** property in the **properties** panel in the bottom left of the designer.
5. To make the Timer service run its TimerEvent every 3 seconds, change the value to **00:00:03**.

   <figure><img src="/files/hHOWV59GHNHQnqKOySnl" alt=""><figcaption></figcaption></figure>
6. In the plugins panel on the right of the Designer, locate an item called **String** (it has a green **STR** prefix) inside of the Linx plugin and **drag it into the tab called TimerEvent**.
7. In the properties panel in the bottom left of the designer, locate the property called **Name** and change the value from **String** to **MyString**.
8. Locate a property called **Value** and enter **Hello World**.

   <figure><img src="/files/rUB2fgPKBzK3jxV6bdxy" alt=""><figcaption></figcaption></figure>
9. Select the **Add plugins** button in the plugins panel on the right of the designer to open the plugins popup.
10. Locate the **File** plugin and select **ADD** to add it to your solution (the initial download might take a moment) and close the popup.

    <figure><img src="/files/B2HfTw46n8SH1aKpi8vX" alt=""><figcaption></figcaption></figure>
11. Open the **File** plugin in the plugins panel and locate the **TextFileWrite** function (it has a blue **FNC** prefix).
12. Drag the **TextFileWrite** function into the **TimerEvent tab** in the center of the designer.

    <figure><img src="/files/UD423ArVTrsQFvxwn6aC" alt=""><figcaption></figcaption></figure>
13. Select the TextFileWrite function in the TimerEvent tab and locate the **File path** property.
14. Enter the path to a text file, such as **c:\temp\file.txt** (the file does not have to exist).
15. Locate the **Contents** property, open the dropdown, select **MyString** and add **+ "\n"** so the property value becomes **=MyString + "\n"** (\n writes a new line character).

    <figure><img src="/files/EQZdBD66M86v85yKqzZb" alt=""><figcaption></figcaption></figure>
16. **Right-click on the Timer** service in the Solution Explorer and select an item called **Debug** to place the Designer into Debug mode.
17. In the **Debug Output** panel at the bottom of the Designer, wait for a message that says **Ready to debug. Click START to start debugging**. When you see it, click the **Start** button in the top left of the Designer.

    <figure><img src="/files/9WDyJMS6mptp4B7nZ0RJ" alt=""><figcaption></figcaption></figure>
18. Every 3 seconds the Timer service fires its event handler (called TimerEvent) which runs the logic it contains. The **Debug Output** panel then shows **Timer Service fired**. When you see a few of these messages you can open the file and see the result of your automation.

    <figure><img src="/files/cn5RaCblZha0zymCBsHZ" alt=""><figcaption></figcaption></figure>

***

## All Steps in a Video

{% embed url="<https://youtu.be/QxLLohS2gBo>" %}

***

## Explanation

When you start the timer service, it fires the TimerEvent event handler every 3 seconds.\
The TimerEvent instantiates a String and assigns a value to it.\
When the TextFileWrite function is called it creates or finds the file in its path property.\
TextFileWrite then writes the output of the variable MyString to the file.

***

## Challenge

If you had fun building this solution in Linx, why not extend it a bit further? Instead of returning a static string:

* Change the value of MyString and debug the service again.
* In the dropdown of the Contents property of the TextFileRead, select the Expression Editor and use this expression **"The time is " + $.System.CurrentDateTime** as the property value.
* Use the CallRESTService function from the REST plugin to call another REST service and assign the ResponseBody property to the contents property of the TextFileRead.
* Use the ExecuteSQL function from the Database plugin to select some data from a database and assign it to the contents property.

***

## Links

* Check out our [samples repo on Github](https://github.com/linx-software/samples) and find out what else you can build with Linx.
* [Linx community posts about Timer Service](https://community.linx.software/community/search?q=Timer).


---

# Agent Instructions: 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:

```
GET https://docs.linx.software/first-applications/automation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
