As a learning exercise, I’m trying to query ScriptDb and return a person’s name when my script has their email address. The function below returns “ScriptDbResult” instead of the correct name (which should be Patrick Farmer – see the list below the function). Can somebody please advise on what I’m doing wrong?
function getNameFromDb() {
var email = "patrickf@spambob.com";
var db = ScriptDb.getMyDb();
var result = db.query(
{Names: {Emails: email}});
Logger.log(result);
}
This is what the Logger shows is in the database:
{
"Emails": "lucaj@spambob.com",
"Names": "Luca Jenkins"
}
{
"Emails": "patrickf@spambob.com",
"Names": "Patrick Farmer"
}
{
"Emails": "elizabethj@trashymail.com",
"Names": "Elizabeth Jennings"
}
{
"Emails": "gabrielr@pookmail.com",
"Names": "Gabriel Ryan"
}
You are almost there. You indeed get back a ScriptDBResult object. You need to fecth results using the next method