> For the complete documentation index, see [llms.txt](https://docs.monokot.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.monokot.io/scripts/programming-examples/how-to-writing-to-tag.md).

# 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).
