async function checkData(){let results = wixData.query(“Diamond”).find();console.log(results, “returns items inside diamond collection”);return results;}$w.onReady(function () {let data = checkData();console.log(data, “returns same as results”);});
I’m trying to add the unique code (simply listed as 1,2,34…) to my subscription orders. I want to be able to download customers and see this code listed with the order on download. I also want the code to go on the thank you page of the subscription customer.
my end goal is to assign a 8-digit alpha numeric code to each customer, but the codes need to come from my file (which in testing is listed as DB codes and rows 1-7). I do not want to repeat any row.
I have tried a couple days without success and would value any input.
Thank you
in my downloaded customers, including subscription, I need the unique code to always be with that customer, and I need to know active payment or not active payment to the subscription with the download.
Hope there is enough her to offer me a next step. All the best, Rob
Ok well, here we have some difficulties…
But at first i want to tell you that you perhaps should learn to use this forum the right way.
- Do not show CODE-PARTS in plain text or in a pic. Do it in CODE-BLOCKs, like the following example…
$w.onReady(async function() {
let RESULTS = await checkData();
console.log("RESULTS: ", RESULTS);
});
function checkData(){
wixData.query("Diamond")
.find()
.then((res)=>{return res.items})
.catch((err)=>{console.log(err);});
}
-
Your code was not right. Take a look onto the given example above.
-
Use the console to investigate your results.
I changed my file name to diamonds but got the following console:
public/pages/masterPage.js: Missing semicolon. (5:6) 3 | $w.onReady(function () { 4 | // Write your code here > 5 | });npm install | ^ 6 |
Loading the code for the site. To debug this code, open masterPage.js in Developer Tools.
Loading the code for the test velo page. To debug this code, open n9x75.js in Developer Tools.
ReferenceError: wixData is not defined
test velo
Line 7
Improve loading time by
turning on caching
for the test velo page.
Learn more
Sound like a syntax-error, but i can not recognize any syntax-errors in my shown code.
If there would be a Syntax-Error → it would be marked in RED
Did you also first imported the wix-data-api ???
import wixData from 'wix-data';
$w.onReady(async function() {
let RESULTS = await checkData();
console.log("RESULTS: ", RESULTS);
});
function checkData(){
wixData.query("Diamond")
.find()
.then((res)=>{return res.items})
.catch((err)=>{console.log(err);});
}
-Your Collection-Name is → “Diamond” ??? You have already double-checked it?
-Your Collection gives also the related permissions to enter your DATABASE ?
Check all your setup.
Use the CONSOLE of your browser for DEBUGGING.
I kept getting “diamonds data doesn’t exist.” When I go to diamonds database it says “need to publish”. Do I need to publish it to make it work? Also, I looked into spelling and the console and realized it was looking for wix-data in the code. Does wix data need to be contact01
Please do not attach pics as downloadable files. Put pics directly into the post, like this…
So you have setted-up some PERMISSIONS, which do allow to enter the DATABASE just by an ADMIN. I would suggest to reduce your PERMISSION-LEVEL to the lowest one → JUST for TESTINGS !!!
If you do not use Preview & Live-Mode, you will have first to PUBLISH your WEBSITE.
ReferenceError: wixdata is not defined
and
WDE0025: The Diamond collection does not exist. You cannot work with a collection using the Data API before it is created in the Editor.
Show your current code please…
Did you publish your site?
masterpage.js
import wixData from ‘wix-data’ ;
$w . onReady ( async function () {
let RESULTS = await checkData ();
console . log ( "RESULTS: " , RESULTS );
});
function checkData (){
wixData . query ( “Diamonds” )
. find ()
. then (( res )=>{ return res . items })
. catch (( err )=>{ console . log ( err );});
}
specific page
$w . onReady ( async function () {
let RESULTS = await checkData ();
console . log ( "RESULTS: " , RESULTS );
});
function checkData (){
wixdata . query ( “Diamonds” )
. find ()
. then (( res )=>{ return res . items })
. catch (( err )=>{ console . log ( err );});
}
…and I opened up all the permissions
Now it is clear!
Why you name your COLLECTION → “diamonds”, but giving it the following ID —> “contact01”?
I would reccommend never to do such unlogical designation, regarding your IDs.
When your Collection is called → Diamonds → then it should have also the same or similar ID → " Diamonds ", or " diamonds ", or something like that, but not → “contact01” → that makes absolutely no sense.
And if you will have about 20-DBs in your project? Than you will go crazy!
So in your case → you used the wrong ID, or better said, you used the name of the collection instead of it’s ID!
You will surely have to RECREATE your DATABASE, until it is not to late.
Setup your IDs right from the beginning in a systematic and logical way and you won’t have any headaches later!
Hi there,
Yes, I suggest that you share your code, letting us know what method you’re using to retrieve the data (datasets or data APIs), explain what exactly you want to do, and most importantly, do not share info as downloadable files, no one likes to download stuff to their machines.
$w . onReady ( async function () {
let RESULTS = await checkData ();
console . log ( "RESULTS: " , RESULTS );
});
function checkData (){
wixdata . query ( “Diamond” )
. find ()
. then (( res )=>{ return res . items })
. catch (( err )=>{ console . log ( err );});
}
import wixData from ‘wix-data’ ;
$w . onReady ( async function () {
let RESULTS = await checkData ();
console . log ( "RESULTS: " , RESULTS );
});
function checkData (){
wixData . query ( “Diamond” )
. find ()
. then (( res )=>{ return res . items })
. catch (( err )=>{ console . log ( err );});
}
Per comments earlier, my database caused confusion and was recreated to eliminate the confusion. Also, it was suggested to open up the permissions. After several trials, I am unable to get it to work. Namely, the wixdata is not defined and collection does not exists.
Any suggestions? Thank you.
You have again the same mistake.
You settep-up your database-ID the wrong way.
- Is it → Diamonds
- or diamonds
- or Diamond
- or diamond
- or DIAMONDS
- or DIAMOND
Please take care on this. It is CASE-sensitive!
This is why your DB does not exists in the error-log.
Case sensitive worked… for part of it.
I’m still getting this error: ReferenceError: wixdata is not defined in this line of code:
wixdata . query ( “Diamond” )
Here is the code:
import wixData from ‘wix-data’ ;
$w . onReady ( async function () {
let RESULTS = await checkData ();
console . log ( "RESULTS: " , RESULTS );
});
function checkData (){
wixdata . query ( “Diamond” )
. find ()
. then (( res )=>{ return res . items })
. catch (( err )=>{ console . log ( err );});
}
" diamond " is the right one!
per chat recommendation, I made a new database with all Capital Diamond. So I am unsure why wixdata is not defined
I put Diamond everywhere to see where it pulls data from, and still get one-error:
ReferenceError: wixdata is not defined in this line of code:
wixdata . query ( “Diamond” )
@robmazemfg
Publish your site and try it again.