Search.../

getCurrentItem( )

Returns the current item.

Description

The getCurrentItem() function returns an object whose key:value pairs are the field keys and field values of the current item, including all hidden fields. Fields that do not have a value are omitted from the returned object.

When called on a write-only or read & write dataset, getCurrentItem() returns the unsaved state of the current item.

Returns null or undefined if the dataset:

  • Is filtered to not match any items in the collection.
  • Is empty.
  • Has not loaded yet.

Note:

A dataset needs to load its data before you call its getCurrentItem() function. Usually a dataset finishes loading a short time after the page it is on finishes loading. So if you call getCurrentItem() inside the page’s onReady() event handler, the dataset might not be ready yet.

To call getCurrentItem() as soon as possible after a page loads, use the dataset's onReady() function inside the page’s onReady() event handler to ensure that both the page and the dataset have finished loading.

If the current item is changed from a non-dataset source, such as by selecting a row in a table connected to a dataset or clicking a button set to advance to the next item in a dataset, the dataset's current item is not updated immediately. Therefore, to get the dataset's new current item, call getCurrentItem() in the dataset's onCurrentIndexChanged() event handler. Do not use the events of the non-dataset source, such as onRowSelect or onClick, to call getCurrentItem() because they will fire before the dataset's current item is updated.

Syntax

function getCurrentItem(): Object

getCurrentItem Parameters

This function does not take any parameters.

Returns

The current item, or null if there is no current item.

Return Type:

Object

Was this helpful?

Get the dataset's current item

Code Example

Copy Code
1let itemObj = $w("#myDataset").getCurrentItem();
2
3/*
4 * {
5 * "_id": "fcec780a-3e37-4b64-8a66-37c552c53f99",
6 * "_owner": "f6c0f9c3-a62d-7e9f-g58d-943829af244d9",
7 * "_createdDate": "2017-05-01T17:19:03.823Z",
8 * "_updatedDate": "2017-05-01T17:19:10.477Z",
9 * "title": "Dr. ",
10 * "name": "B",
11 * "link-dynamic-name": "/myCollection/B"
12 * }
13 */
Get the dataset's current item when the page loads

Code Example

Copy Code
1$w.onReady( () => {
2 $w("#myDataset").onReady( () => {
3 let itemObj = $w("#myDataset").getCurrentItem();
4
5 } );
6
7} );
8
9/* itemObj:
10 *
11 * {
12 * "_id": "fcec780a-3e37-4b64-8a66-37c552c53f99",
13 * "_owner": "f6c0f9c3-a62d-7e9f-g58d-943829af244d9",
14 * "_createdDate": "2017-05-01T17:19:03.823Z",
15 * "_updatedDate": "2017-05-01T17:19:10.477Z",
16 * "title": "Dr. ",
17 * "name": "B",
18 * "link-dynamic-name": "/myCollection/B"
19 * }
20 */