---
url: /statelake/scripting-reference/events/record-level-events/linkeddata-event.md
---

# LinkedData Event

This is a special **Event** that sets and creates a link to the source dataset.

Setting **LinkedData** indicates that the processing of the dataset should be looped and executed once for each record in the source data set - the linked dataset.

If **LinkedData** is set to a source dataset, you will get one record in the destination dataset for each record in the source dataset, because the script engine will repeat the processing of the dataset until it reaches the end of the source dataset. If there are 10 records in the source, then the dataset will process 10 times and end up containing 10 records. If however the linked dataset does not contain any records, then you will not get any records in the destination.

If **LinkedData** is not set, then the dataset will only process once - you will get one record in the destination dataset even if there are no records in the source dataset. You can only prevent the engine from creating this one record by either linking it to a dataset that contains no records, or by skipping the record through use of the **BeforeMap** event.

The **LinkedData** **Event** has one parameter called **LinkedData**. This parameter should be set to the name of the dataset you want to link to.

## Setting The LinkedData Event

You can set the **LinkedData Event** by dragging a dataset from the source and dropping it on the destination dataset. This will set the **LinkedData** parameter of the **Event**.

However, this drag-and-drop procedure will have no affect if the **Event** is already set, in which case you should edit the **Event** manually or remove it and then re-set it by another drag-and-drop.

When editing the **LinkedData** event manually, you can also drag a dataset from the source and drop it within the script editor.

The following is an example of a **LinkedData Event** in a script, setting a ink between the source **ORD_HEAD** dataset and the destination **ORDER_HEADER** dataset.

```pascal
procedure LinkedDataEvent(var LinkedData:TdaQueryDataView);   // ORDER_HEADER
begin
  LinkedData := ORD_HEAD;
end;
```

The **LinkedData Event** will usually be called many times within a **Map** - approximately once for each record in each source dataset.

Typically, the linked dataset will be set by the first call and will not be changed by subsequent calls, but this does not have to be the case, and repeated calls to **LinkedData** allow the source datasets to be changed during processing.

For example, processing could be switched to a second source dataset when end-of-file is detected on the first one.

A successful **LinkedData Event** will be displayed in **green** in the **Map**.
