Hi, I created a simple login page that verifies the item and then creates a random string, updates the item’s field to include this string and then directs to a dynamic page that uses this field in its URL. I had everything working perfectly but had to delete and replace the original database. Now I cannot update this new database like before. I have given it a different name, checked the permissions and all references to it. Am I missing something in the code or is this a problem with my database? Thanks in advance.
console.log('wstudentselearning/' + firstItem.newSchoolUrl)
This line of code returns as: wstudentselearning/undefined
import wixData from 'wix-data';
import wixLocation from 'wix-location';
$w.onReady(function () {
setTimeout(function (parameter) {
$w("#anchor4").scrollTo()
}, 1000)
$w("#button2").hide();
$w("#button3").hide();
$w("#errorMessage").hide();
$w('#button1').onClick(function () {
let schoolLogin = $w('#input1').value + $w('#input2').value;
console.log(schoolLogin);
return wixData.query("wstudentselearning")
.eq("schoolLogin", schoolLogin)
.find()
.then((results) => {
let firstItem = results.items[0];
let schoolRoll = results.items[0].schoolRollNumber;
console.log(firstItem)
console.log(schoolRoll)
if (!firstItem) {
console.log(results);
$w("#button2").hide();
$w("#button3").show();
$w("#errorMessage").show();
$w('#button3').onClick(function () {
wixLocation.to('/contact');
})
} else {
function gCharOne() {
let possible = "abcdefghijklmnopqrstuvwxyz";
return possible.charAt(Math.floor(Math.random() * possible.length));
}
console.log(gCharOne())
function gCharTwo() {
let possible = "abcdefghijklmnopqrstuvwxyz";
return possible.charAt(Math.floor(Math.random() * possible.length));
}
console.log(gCharTwo())
function gCharThree() {
let possible = "abcdefghijklmnopqrstuvwxyz";
return possible.charAt(Math.floor(Math.random() * possible.length));
}
console.log(gCharThree())
function gCharFour() {
let possible = "abcdefghijklmnopqrstuvwxyz";
return possible.charAt(Math.floor(Math.random() * possible.length));
}
console.log(gCharFour())
function gCharFive() {
let possible = "abcdefghijklmnopqrstuvwxyz";
return possible.charAt(Math.floor(Math.random() * possible.length));
}
console.log(gCharFive())
function gCharSix() {
let possible = "abcdefghijklmnopqrstuvwxyz";
return possible.charAt(Math.floor(Math.random() * possible.length));
}
console.log(gCharSix())
let url = (schoolRoll + gCharOne() + gCharTwo() + gCharThree() + gCharFour() + gCharFive() + gCharSix());
console.log(url)
async function updateUrl(){
firstItem.newSchoolUrl = url;
await wixData.update("wstudentselearning",firstItem);
}
console.log("--UPDATED--")
console.log('wstudentselearning/' + firstItem.newSchoolUrl)
wixLocation.to('/wstudentselearning/' + firstItem.newSchoolUrl);
}
})
.catch((err) => {
let errorMsg = err;
$w("#button2").hide();
$w("#button3").show();
$w("#errorMessage").show();
console.log(errorMsg);
})
});