new( )
Deprecated.
This function will continue to work, but a newer version is available. Use the
add()
function instead.
Description
Creates a new blank item.
The new()
function saves the current item and then creates a new blank
item. When the editing of the new item is complete, you will need to
call another function that will save the new item.
The index of the new item is one after the index of the current item, or zero if there is no current item.
Note that since the new()
function begins by saving the current item,
if the current item cannot be saved for any reason, such as it does not
pass validation, calling the function will cause an error.
Calling new()
on a read-only dataset causes an error.
Note:
A dataset needs to load its data before you call its
new()
function. Usually a dataset finishes loading a short time after the page it is on finishes loading. So if you callnew()
inside the page’sonReady()
event handler, the dataset might not be ready yet.To call
new()
as soon as possible after a page loads, use the dataset'sonReady()
function inside the page’sonReady()
event handler to ensure that both the page and the dataset have finished loading.
Syntax
function new(): Promise<void>
new Parameters
This function does not take any parameters.
Returns
Fulfilled - When a new empty item is the current item of the dataset. Rejected - An error message.
Return Type:
Was this helpful?
1// NOTE: This example uses the new add()2// function, which replaces new().3// See the function description for more information, and4// line 14 for the deprecated example.56$w("#myDataset").add()7 .then( ( ) => {8 console.log("New item created");9 } )10 .catch( (err) => {11 let errMsg = err;12 } );1314// NOTE: This example uses the deprecated new() function.1516 $w("#myDataset").new()17 .then( ( ) => {18 console.log("New item created");19 } )20 .catch( (err) => {21 let errMsg = err;22 } );
1// NOTE: This example uses the new add()2// function, which replaces new().3// See the function description for more information, and4// line 20 for the deprecated example.56$w.onReady( () => {7 $w("#myDataset").onReady( () => {8 $w("#myDataset").add()9 .then( ( ) => {10 console.log("New item created");11 } )12 .catch( (err) => {13 let errMsg = err;14 } );1516 } );1718} );1920// NOTE: This example uses the deprecated new() function.2122$w.onReady( () => {23 $w("#myDataset").onReady( () => {24 $w("#myDataset").new()25 .then( ( ) => {26 console.log("New item created");27 } )28 .catch( (err) => {29 let errMsg = err;30 } );3132 } );3334} );