Beacon prefill function - javascript

I already set up the Beacon 'identify' stuffs, and can open up using Beacon("open");
But when I try to use prefill function, i'm getting some error.
Beacon("prefill", {
name: "Steve Aoki",
email: "steve#aoki.com",
subject: "Need help with invoice",
text: "Hello, I need some help with my invoice. See attached.."
})
Error: Uncaught TypeError: Cannot read property 'filter' of undefined
Any code that I missed? Thanks in advance.
Reference here

You need to have a fields array, because in the example you posted, the one thing your code doesn't have is a fields array. This is also shown because filter is an array method, and calling fields.filter when you don't have fields will result in an undefined error.

Related

FirebaseError: Function setDoc() called with invalid data. Unsupported field value: undefined

OrderDetails Logged image
I want to save order details to my firestore db,Here my orderDetails:
const orderDetails=[{
id:"ID1",
name:"foo"
},
{
id:"ID2",
name:"foo-foo"
},
]
Here is the code for adding this order Details to fire store:
.then(({paymentIntent})=>{
if(user){
console.log(basket);
const userRef=doc(db,'shopDB',user.uid);
const userOrderRef=doc(userRef,'userOrderInfo',paymentIntent.id);
setDoc(userOrderRef,{
orders: basket,
created :paymentIntent.created,
amount :paymentIntent.amount
},{merge:true})
Here all working if i set document without orderDetails,Other two values will added to fire store,but when i try to add orders to database it throws error
error>>>>>>>>>>>
FirebaseError: Function setDoc()
called with invalid data. Unsupported
field value: undefined
Can anyone help me with this?
looks like 1 of the 2 missing:
orderDetails is undefined
userOrderRef is undefined
try printing them both to make sure what's missing there
Edit:
now that I can see your console.log, your issue is with field alternative:undefined at element in index 1 according to your photo.
remove this property before trying to save it on firestore

Can only access some javascript object keys

I am noticing strange behavior from a javascript object in my Node application. The user object is created by parsing a csv file with two columns: Email and ID. For some reason, I can only access one of the fields using the typical methods. The other field always returns undefined. I am using Node 15.12.0.
When I log the user object, it returns: { 'Email': 'email#example.com', ID: '12345' }
Curiously, the ID field does not have quotes when it is logged, but the Email field does have quotes.
I can access user.ID as usual, but user.Email returns undefined.
console.log(Object.keys(user)); // [ 'Email', 'ID' ]
console.log(user.ID); // 12345
console.log(user.Email); // undefined
console.log(user['Email']) // undefined
console.log(user["Email"]) // undefined
console.log(user.email) // undefined
console.log(user["\'Email\'"]) // undefined
console.log(user["'Email'"]) // undefined
console.log(user[Object.keys(user)[0]]) // email#example.com
console.log(Object.values(user)[0]) // email#example.com
I have tried the using JSON.parse(JSON.stringify(user)), but I get the same results as before.
The only way I can access the Email field is by using the user[Object.keys(user)[0]] or Object.values(user)[0] which is very strange to me.
I would appreciate any ideas you have to figure out whats happening here. Is there something I can do to examine the object more closely? Does the quotes around the keys indicate anything?

Reading from JSON returns undefined

I'm trying to read from a JSON that contains my error messages, so that in case I'd ever want to change what my error messages say, I'd just change the JSON instead of diving into my source code. Everything seems to be working fine...
var fs = require('fs')
console.log("Now reading from error messages configuration file...");
var errorMsgs = JSON.parse(fs.readFileSync('config/error_msgs.JSON'));
console.log(errorMsgs)
This is what's in errorMsgs.json:
{
"bad_password" : [
{
"error" : "Incorrect login credentials.",
"details" : "This happens if you either have an incorrect username or password. Please try again with different credentials."
}
],
"missing_fields" : [
{
"error" : "Credentials failed to parse.",
"details" : "This happens when one or more fields are missing (or have illegal characters in them), please try again with different credentials."
}
]
}
When I log to the console, errorMsgs displays fine. When I log one of the items that errorMsgs has (like bad_password), it also works fine, as in it displays the items that are nested inside. However, when I attempt to retrieve a specific value like errorMsgs.bad_password['error'], it returns undefined. I can't seem to figure it out. I tried dot notation (errorMsgs.bad_password.error), which returns undefined. I tried the method above (errorMsgs.bad_password['error']) which also returns undefined. Asking for the typeof of errorMsgs, it returns object, which I assume makes it not a string. Passing the value to a variable first and then logging the variable doesn't do anything either. Is node converting it to a string on-the-fly, causing it to return undefined, or am I just doing something wrong?
bad_password" : [
{
"error" : "Incorrect login credentials.",
"details" : "This happens if you either have an incorrect username or password. Please try again with different credentials."
}
],
Your nested object is contained in an array.
errorMsgs.bad_password[0]['error']
This is what you're looking for. Just grab the first value of the array

Mongoose, resolve path in embedded array

I have the following Mongoose schema:
var WeekSchema = new Schema({
days: [{
name: String
}]
});
and I want to get 'name' and do something with it (lets assume a validation).
So, I try to validate using the following code:
WeekSchema.path('days.name').validate(function(value){
return /monday|tuesday|wednesday|thursday|friday|saturday|sunday/i.test(value);
}, 'Invalid day');
but i get the error:
WeekSchema.path('days.name').validate(function(value){
^
TypeError: Cannot call method 'validate' of undefined
in fact if I print the resolved path with
console.log(WeekSchema.path('days.name'));
I have 'undefined'.
The question is, how can I get 'name' by using its path?
I met this issue today so I did a little research by printing out the main path, in your case: console.log(JSON.stringify(WeekSchema.path('days'), null, 4)); Then I figured out the path to the sub docs to be:
WeekSchema.path('days').schema.path('name');
This is my first answer here, hope it helps :)

Can't override property of an JavaScript object

I got a method that is formatting the date property of a message. A user has an array of messages.
user.messages[i].date = formatDate(user.messages[i].date);
// logs the correctly formatted date
console.log(formatDate(user.messages[i].date));
// logs the unformatted date
console.log(user.messages[i].date);
However, when I do it like the following code snippet it works.
user.messages[i] = {
name: user.messages[i].name,
body: user.messages[i].body,
_id: user.messages[i]._id,
date: formatDate(user.messages[i].date)
};
With the help of the comment from #plalx, I found a solution in this thread:
Stubbing virtual attributes of Mongoose model
This is a guess but you could add formatteddate:"" into your user model (or similar) and then try:
user.messages[i].formatteddate = formatDate(user.messages[i].date);
Therefore you are not re-configuring it.

Categories

Resources