[SOLVED] How to get _id of a recently inserted record so you can use it as your Primary Field.

Can you elaborate on that? I’m quite new to this. From what I know, the _id is only generated once a record has been created. That’s why I used AfterSaveHandler . _id to get the _id and then hopefully insert it in clientId field of the same record.


EDIT
I tried the toUpdate method and it does successfully copy the _id to the clientId field however, the rest of the fields become empty since it requires all of the fields to be updated as well.

I also tried the toSave method and it does the same thing, it clears the rest of the fields.

export function submitBtn_click(event) {
    $w('#dataset1').setFieldValue('createdBy', $w('#currentUserField').value)
    $w('#dataset1').onAfterSave((AfterSaveHandler) => {
      console.log("This is the ID of the new record: "+ AfterSaveHandler._id)

      let clientID = AfterSaveHandler._id
      //SAVE
      let toSave = {
         "_id":        clientID,
         "clientId":   clientID
      };

      wixData.save("test", toSave)
      .then( (results) => {
            let item = results; 
         } )
         .catch( (err) => {
            let errorMsg = err;
         } );
      })