Hello,
I am working on the following code to try to get certain pricing for clients from a dataset (thank you Giri!), however, I am getting a couple of errors that i have been unable to resolve. I am hoping someone can assist.
Line 10: Expected a conditional expression and instead saw an assignment
Line 26: Assigning to rvalue
Then when i preview i get the following errors:
Code Text:
import {local} from ‘wix-storage’;
import wixLocation from ‘wix-location’;
import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
$w.onReady(function () {
$w(“#CompleteMenu”).onReady( () => {
let user = wixUsers.currentUser;
let userRole = user.role;
if (userRole = “Member”) {
$w(“#Box1”).hide();
user.getEmail()
.then((rsemail) => {
let userEmail = rsemail;
let thistestCode = $w(‘#CompleteMenu’).getCurrentItem().testcode;
wixData.query("Client")
.eq("Email_id", userEmail)
.eq("Test Code_id", thistestCode )
.descending("date_created")
.find()
.then((results) => {
if (results.totalCount) {
let items = results.items ;
let firstItem = items[0];
$w(“#txtPrice”) = firstItem.Price_id ;// this puts the price into the text
else {
$w(“#Box1”).show();
$w(“#btnLogon”).hide();
$w(“#txtRemarks” = “Sorry, no pricing available, please contact us”);
}
}
})
.catch((err) => {
let errorMsg = err;
});
});
}
- Fixed
- Still getting the same error
$w(“#txtPrice”) = firstItem.Price_id.text ;
Also Tried
$w(“#txtPrice”).text = firstItem.Price_id ; // this puts the price into the text
That gives me an error on next line: unexpected token
else {
That gives me an error on next line: unexpected token
else {
Looks like there is a closing bracket } missing before the THEN, closing off the former IF
If i am correct there was also a missing parenthesis
})
Either way i still get the “else” unexpected token
.then((rsemail) => {
let userEmail = rsemail;
let thistestCode = $w('#CompleteMenu').getCurrentItem().testcode;
wixData.query("Client")
.eq("Email_id", userEmail)
.eq("Test Code_id", thistestCode)
.find();
})
.then((results) => {
if (results.totalCount) {
let items = results.items ;
let firstItem = items[0];
$w(“#txtPrice”).text = firstItem.Price_id; // this puts the price into the text
else {
$w(“#Box1”).show();
$w(“#btnLogon”).hide();
$w(“#txtRemarks” = “Sorry, no pricing available, please contact us”);
}
})
}
There is still no closing bracket before the ELSE in question, which there should be, And for the next upcoming error, the
$w(“#txtRemarks”
should be
$w(“#txtRemarks”).text
Thank you for your patience, Giri, it’s much appreciated. Now I am getting an error with the .catch “unexpected Token”
.then((results) => {
if (results.totalCount) {
let items = results.items ;
let firstItem = items[0];
$w(“#txtPrice”).text = firstItem.Price_id;
}
else {
$w(“#Box1”).show();
$w(“#btnLogon”).hide();
$w(“#txtRemarks”).text = “Sorry, no pricing available, please contact us”;
}
});
}
**.catch( (err) => {**
console.log(err);
});
});
});
David, it´s a bracket error. I can´t see the whole code as it is, so I can´t help you with that. But it´s quite easy (but time consuming): just indent code after every bracket that is not closed on the same line, put the closing } or ) underneath it (same indent) and eventually you will find the error.
Hi Giri, fixed that problem. It was an extra semicolon ;
However, when i login to test the code it the price isn’t listed.
I have to collections:
- CompleteMenu
a) Testcode
- Client
a) Email_id
b) Test Code_id
c) Price_id
Price text= txtPrice
Box= Box1
Login Button= btnLogon
Text= txtRemarks
Closing bracket on line 11 shouldn´t be there, it closes the IF-statement immediately. Wild guess: line 36 is where it should be? Also, are you sure that the field name is actually called Test Code_Id, I mean with the blank? Are you sure you are looking at the field name, not the label text?
ALso, did you do the test on totalcount as I mentioned earlier? And the sort is gone. Maybe you did this because a NO SORT returns the resultset by default sorted on creationdate, I think I remember having read that somewhere?
Test Code_id
I am supposed to be using the field name from the Client collection, right?
Updated Code w/ sort
Still doesn’t work :/. For the total count it returns nothing when logged in
Figured it out. Thank you so much for your help and patience, Giri.
It was missing a Return function on the Client Data Query.
return wixData.query(‘Client’)
If anyone else needs this in the future the code is below:
import wixLocation from ‘wix-location’;
import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
$w.onReady(function () {
$w(“#CompleteMenu1”).onReady(() => {
let user = wixUsers.currentUser;
let isLoggedIn = user.loggedIn;
let userRole = user.role;
if (userRole === “Member”) {
$w(“#Box1”).hide();
user.getEmail()
.then((email) => {
let userEmail = email;
let thistestCode = $w(“#CompleteMenu1”).getCurrentItem().title_id;
return wixData.query(‘Client’)
.eq(“Email_id”, userEmail)
.eq(“Test Code_id”, thistestCode)
.descending(“_createdDate”)
.find();
})
.then((results) => {
if (results.totalCount) {
let items = results.items;
let firstItem = items[0];
$w("#txtPrice").text = firstItem.Price_id;
} else {
$w("#Box1").show();
$w("#btnLogon").hide();
$w("#txtRemarks").text = "Sorry, no pricing available, please contact us";
}
})
.catch((err) => {
console.log(err);
});
}
});
});