---
url: /statelake/scripting-reference/events/field-level-events/onmap-event.md
---

# OnMap Event

The **OnMap Event** is the main **Event** for providing script code against fields. You can alternatively split the script and attach some to the **BeforeMap Event** and **AfterMap Event** of the field, however this is rarely used. It is far easier to have the entire script against the **OnMap Event**.

The **OnMap Event** has one parameter called **Value**. This parameter represents the value of whatever has been specified in the code.

The field-level **BeforeMap Event** and **AfterMap Event** on the field also have a **Value** parameter that represents the value of the field.

All of the field-level **Events** have a symbiotic relationship.

Any **Value** set in the field's **BeforeMap Event** will be the starting **Value** of the **OnMap** **Event**. Similarly, any **Value** set in the **OnMap Event** will be the starting **Value** of the field's **AfterMap Event**. The **BeforeMap Event** and **AfterMap Event** at field-level are rarely used as there is no real advantage - control is primarily left to the **OnMap Event**.

## Setting The OnMap Event

You can drag fields from the source **Data Definition** and drop them on the destination field to automatically create a script.

You can further edit the script within the script editor.

Alternatively you can create it from scratch by selecting the field and clicking anywhere within the script editor area of the screen. The **OnMapEvent** skeleton code will automatically be generated, and as the following examples illustrate, you can add whatever script is necessary to set the value of the field.

```pascal
procedure OnMapEvent(var Value:Variant);  //STOCKCODE
begin
  Value := PODETAIL['POdetail_SupplierItemCode'].Value;
end;
```

```pascal
procedure OnMapEvent(var Value:Variant);  //X_FLOID
begin
  Value := -1; // reset flag to allow (re-)processing
end;
```

```pascal
procedure OnMapEvent(var Value:Variant);  //ORDER_NO
begin
  Value := 'ORD ' + ORD_HEAD['ORDER_NO'].Value;
end;
```
