Script fails to load serial # before save

There is a database call “Exhibitors”, it contains information about the people. Namely, their abbreviations for the Kennel, field key is abb and is 2-5 letters long chosen by the exhibitor
There is a second database called “Registry”, it contains information about the gerbils, each gerbil should have an sequential number. I have the fields abb, serial, gerbil_id, and gerbil_name

The end goal is to have the gerbils with two parts to their unique gerbil_id concatenated using the fields abb + serial, to give results like MS1001, MS1002, MS1003 while another exhibitor might be SRG1001, SRG1002, SRG1003, a less desirable solution would be to have the results be MS1001, SRG1002, MS1003, MS1004, SRG1005, MS1006 as the serial number is generated based on creation date and not filtered by exhibitor.


hook:

import wixData from "wix-data"; 
export function Registry_beforeInsert(item, context) {
 return wixData.query("Registry")
        .limit(1)
        .descending('serial') 
        .find()
        .then((results) => {
 if (results.length === 0) {
                item.serial = 1000; 
            } else {
 const lastItemInCollection = results.items[0]; 
                item.serial = lastItemInCollection.serial + 1;
            }
 return item; 
        });
}


on page

import wixData from 'wix-data';
$w.onReady(function  () {
 const record = {
 "serial": 0
};

$w("#Registry").onReady( () => {
    $w("#Registry").new()
      .then( ( ) => {
        $w("#Registry").setFieldValue("gerbil_id", $w("#abb").value + $w("#serial").value );
        $w("#Registry").save();
      } )
      .catch( (err) => {
 let errMsg = err;
      } );
  });
})


The script fails at this line. It will only save the abb field to the gerbil_id field, it will not save the serial field, as that field is not populating unitl i click submit.

$w(“#Registry”).setFieldValue(“gerbil_id”, $w(“#abb”).value + $w(“#serial”).value );

I think i need to change either the .onReady to a function (and I’m not sure how to accomplish that),

Or more simply, i need to create a more robust before insert, that will create the gerbil_id field i actually want. and I’m not sure how to do that either.