Get dynamic page id while adding content to a wix code form by user.

Hi @thrishtilabs ,

If I understand correctly, you’re using database item ID (_id field) as dynamic page ID.

When a new dataset item is created, its ID is available from the very beginning:

$w.onReady(() => {
  const dataset = $w("#dataset1");
  dataset.onReady(async () => {
    await dataset.new();
    const { _id } = dataset.getCurrentItem();
    console.log(_id);
  });
});

By the way, the recommended approach for form data submission is to use a write-only dataset. With a write-only dataset new item doesn’t need to be created explicitly — it’s already created:

$w.onReady(() => {
  const dataset = $w("#dataset1");
  dataset.onReady(() => {
    const { _id } = dataset.getCurrentItem();
    console.log(_id);
  });
});

Also dataset submission handler takes the item before save and the item after save as the arguments (wix-dataset - Velo API Reference - Wix.com):

export function dataset1_afterSave(itemBeforeSave, itemAfterSave) {
  console.log(itemBeforeSave._id);
  console.log(itemAfterSave._id);
}