Well I can’t see any issue with the code but I do believe this might be a logical error rather than a syntax error.
You are fetching the current application id from the DB and then incrementing it by 3.
But on looking at the screenshot you’ve provided, the uniID field appears to be blank
So when you’re using code to fetch it for the first time, its probably fetching the uniID as undefined or null and when you do null + 3 it results in a NaN (Non assigned Number) and maybe that is the reason behind the issue. Try adding a 0 in the field and then give it a go, and if it still does not work, try replacing your frontend code with the one I’ve provided below:
import wixData from 'wix-data';
import { session } from 'wix-storage-frontend';
import { process } from 'backend/submitT4.jsw';
//Variables
const collectionAppID = "AppID";
const appIDKey = "bc5e76e2-6b5e-4099-8392-9ede9be72d34";
let appNumberInc = 3;
var newAppID = 0;
function getApplicationID(collectionAppID, appIDKey, appNumberInc) {
wixData.get(collectionAppID, appIDKey) //read base number from CMS
.then((item) => {
if (item.appId) {
newAppID = (item.appId + appNumberInc); //Increment by 3 after fetching
session.setItem("AppKey", newAppID); //Set session key with incremented value
} else {
newAppID = appNumberInc; // if app id undefined or zero, then set app id as 3
session.setItem("AppKey", newAppID); //Set session key with incremented value
}
})
}
export function SubmitT4_click(event) {
//Validate and Send data to T4 DB
if ($w('#firstName').valid &&
$w('#lastName').valid) {
//Create an object
let objTb = {
//Token
//token: $w('#captcha1').token,
//nested wix-data obj
wix_data_obj: {
firstName: $w('#firstName').value,
lastName: $w('#lastName').value,
uniID: newAppID //Send number to CMS as part of the object
// uniID: uniID: session.getItem("AppKey") //Doesn't work
// uniID: newAppID //Send number to CMS as part of the object
// uniID: session.getItem("AppKey")
// uniId: session.getItem("AppKey").toString()
// uniID: myNumber //tried using let, const, var - nothing working?
}
};
//Send object to the backend & receive response
process(objTb)
.then((res) => {
if (res.success) {
$w('#dbSuccessText').show();
//wixLocation.to(`${wixLocation.url}`); //refresh page if sucess
}
});
} else {
$w('#dbErrorText').show();
}
}
$w.onReady(function () {
//at page load call function for new application ID
getApplicationID(collectionAppID, appIDKey, appNumberInc)
//Get session value using key
$w('#textNumber').text = session.getItem("AppKey"); //Text display
console.log(session.getItem("AppKey"));
});