# Add a field on the fly

Add a field on the fly by using the [AddFieldFromExpression method](https://help.qlik.com/en-US/sense-developer/November2025/Subsystems/EngineJSONAPI/Content/service-doc-addfieldfromexpression.htm).

Information noteThe expression of a field on the fly is persisted but not its values.

## Example

[](https://help.qlik.com/en-US/sense-developer/Subsystems/EngineAPI/Content/Sense_EngineAPI/WorkingWithAppsAndVisualizations/CreateVisualizations/add-field-on-fly.htm)

#### The goal is to add a field on the fly in the app and use this field in a list object.

1. Add the field Lengths in the app.

The client sends:

```
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "AddFieldFromExpression",
  "handle": 1,
  "params": [
    "Lengths",
    "=len(Country)"
  ]
}
```

The engine returns:

```
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "qSuccess": true
  },
  "change": [
    1
  ]
}
```

The field is successfully added to the app.

2. Create a list object in the app. The dimension of the list object is the field Lengths (set in qFieldDefs) that has been added on the fly.

The client sends:

```
{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "CreateSessionObject",
  "handle": 1,
  "params": [
    {
      "qInfo": {
        "qId": "",
        "qType": "ListObject"
      },
      "qListObjectDef": {
        "qStateName": "$",
        "qLibraryId": "",
        "qDef": {
          "qFieldDefs": [
            "Lengths"
          ],
          "qFieldLabels": [
            "Label"
          ],
          "qSortCriterias": [
            {
              "qSortByLoadOrder": 1
            }
          ]
        },
        "qInitialDataFetch": [
          {
            "qTop": 0,
            "qHeight": 1,
            "qLeft": 0,
            "qWidth": 1
          }
        ]
      }
    }
  ]
}
```

The engine returns:

```
{
  "jsonrpc": "2.0",
  "id": 2,
  "result": {
    "qReturn": {
      "qType": "GenericObject",
      "qHandle": 2
    }
  },
  "change": [
    2
  ]
}
```

The list object is created and has 2 as a handle.

3. Get the first three values of the list object (qHeight is 3 and qTop is 0).

The client sends:

```
{
  "jsonrpc": "2.0",
  "id": 3,
  "method": "GetListObjectData",
  "handle": 2,
  "params": [
    "/qListObjectDef",
    [
      {
        "qTop": 0,
        "qLeft": 0,
        "qHeight": 3,
        "qWidth": 1
      }
    ]
  ]
}
```

The engine returns:

{ "jsonrpc": "2.0", "id": 3, "result": { "qDataPages": [ { "qMatrix": [ [ { "qText": "13", "qNum": 13, "qElemNumber": 0, "qState": "O" } ], [ { "qText": "14", "qNum": 14, "qElemNumber": 1, "qState": "O" } ], [ { "qText": "8", "qNum": 8, "qElemNumber": 2, "qState": "O" } ] ], "qTails": [], "qArea": { "qLeft": 0, "qTop": 0, "qWidth": 1, "qHeight": 3 } } ] } }

The first three values are returned. They give the length of the field Country.