Data Collection -- user input from multiple pages in same row?

newEntry was just the variable name I chose; it has no significance.

Using session data seems reasonable, if you want 1 user to be putting data in from each page.

After using insert, it returns the object that was inserted. You can get the ID value from there. You don’t need to use an afterInsert().

Keep in mind that if the user can enter the page data in either order, each page will need to have both functionality. Possibly check if the session data exists to decide if you need to generate a new entry, or modify an existing one.

Again, generic untested code - just to use for reference :slightly_smiling_face:

import wixData from ‘wix-data’ ;
import {session} from ‘wix-storage’ ;

function PageOne()
{
// Create an object to be entered into the database.
let newEntry = {
‘data1’ : ‘DataFromPage1’ ,
}

// Insert the object into the database.
wixData.insert( ‘MyDatabase’ , newEntry)
.then( result => {
// Get the ID that was just inserted.
let myID = result._id;

// Save the ID to session data.
session.setItem( ‘userDatabaseID’ , myID );
})
}

function PageTwo()
{
// Get the ID from session data.
let myID = session.getItem( ‘userDatabaseID’ );

// Get the object from the database.
wixData.get( ‘MyDatabase’ , myID)
.then( results => {
// Modify the object.
results.data2 = ‘DataFromPage2’ ;

// Update the modified object back into the database.
wixData.update( ‘MyDatabase’ , results);
})
}