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

![](https://4282443477-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3cwznMbQcEQxtnjiRDYX%2Fuploads%2F2S5VDma1Z77OFEB0mKLG%2FHow%20to_%20Writing%20to%20Tag%20\(360041583892\)_image-0.png?alt=media\&token=13084fd6-8cdc-49b2-a3db-f2c8a9ade87e)

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>](https://docs.monokot.io/scripts/api/mosutils).
