---
url: >-
  /statelake/scripting-reference/classes/dataset-class-tdataset/tdataset-query.-.fields.count.md
---

# TDataset\[Query.].Fields.Count

Returns the field count for the **Dataset**.

When using the **Fields.Count** property with a *Source* or *Destination* **Dataview**, .Query must be included as shown in the example below. But when using the property with a script dataset (including the global datasets Data1, Data2, etc), .Query is not included.

Remember, that \<DataviewName> in these examples is a placeholder for the actual name of your *source* or *destination* **Dataview** as per your **Map**. or your *source* **Dataview** for a custom script.

```pascal
procedure OnMapEvent(var Value:Variant);
begin
  LogInfo('Dataview has ' + IntToStr(<DataviewName>.Query.Fields.Count) + ' fields');
end;
```

Also note that for a .Query dataset for a **Dataview**, the dataset will include any fields added by **Statelake**, such as **ID** and **MASTER_ID** for a **Dataview** associated with a **File Definition**, or **Magic SQL** fields for a **DB Definition**.

**Declaration**: property Fields.Count : integer

The following example shows the use of the **Fields.Count** property where there is no **Dataview**. The placeholder \<DatasetName> has been used as a placeholder for the actual **Dataset** name.

```pascal
procedure OnMapEvent(var Value:Variant);
begin
  LogInfo('Dataset has ' + IntToStr(<DatasetName>.Fields.Count) + ' fields');
end;
```
