# How to: Writing to Tag

The guide demonstrates how to create an expression that writes the control signal if the threshold value is exceeded or decreased. Before starting, create a Modbus device and two tags named *monitoring\_tag* (WORD, 16-bit unsigned integer) and *control\_tag* (BOOLEAN).

Open Monokot Server Administrator and double-click *Scripts* on the *Server Explorer* pane. Click *New Expression* and set the name *Writer* for the expression that appears. Insert the following code into the expression code editor:&#x20;

```javascript
// Declaring a limit as a constant
const LIMIT = 100;

// Getting the tag value
var value = context.data['monitoring_tag_trig'].state.value;

if (value > LIMIT)
  return MosUtils.writeTagValueSync('control_tag', true);
else
  return MosUtils.writeTagValueSync('control_tag', false);
```

Press *Ctrl + Enter* to apply the change in the code editor.&#x20;

Go to the *Triggers* tab and click *Add Data...*. Select the tag *monitoring\_tag* created earlier as the data source for the trigger. Enter the name (key) *monitoring\_tag\_trig* for the trigger.

![](/files/n8O86FEFidCvvmXD2zls)

In order for the changes to take effect on the server, click the Sync button. Thus, the expression will be executed each time the *monitoring\_tag* is changed. If *monitoring\_tag* exceeds 100, *control\_tag* will be set to *True*, otherwise *False*.

You can read more about the *MosUtils* object [<mark style="color:blue;">here</mark>](/scripts/api/mosutils.md).


---

# 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.monokot.io/scripts/programming-examples/how-to-writing-to-tag.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.
