Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
Pase el valor de la variable de la función interna a la función contenedora en javascript

Estoy usando hojas de Google con OAuth 2.0

Tengo una función donde llamo

 await createSpreadsheetEntry(body, submittedValues, logger).then( function (value) { console.log(value); }, function (error) { console.log("error in promise: " + error); } );

Mi problema es que el valor siempre está vacío cuando proviene de esto.

 async function createSpreadsheetEntry(body, submittedValues, logger) { var value1 = ""; var value2 = ""; const doc = new GoogleSpreadsheet(process.env.SHEET_KEY); try { await doc.useServiceAccountAuth(creds, SCOPES); console.log("Authenticated to Google"); } catch (error) { logger.error("Error while authenticating: " + error); } const client = new google.auth.JWT( creds.client_email, null, creds.private_key, ["https://www.googleapis.com/auth/spreadsheets"] ); var sheetId = process.env.SHEET_KEY; client.authorize(function (err, tokens) { if (err) { console.log("err: " + err); return; } const gsapi = google.sheets({ version: "v4", auth: client }); const opt = { spreadsheetId: sheetId, range: "Sheets1!A1:J1" }; var request = { spreadsheetId: sheetId, range: "Sheet1!A1:B10", auth: client, }; sheets.spreadsheets.values.get(request , function (err, response) { if (err) { console.log("err: " + err); return; } var vArray = response.data.values.find((document) => { return document[0] == body.user.username; }); value1 = vArray [1]; console.log("v: " + vArray[1]); }); return value1; }); return { val1: value1, val2: value2}; }

En otras palabras, veo el valor correcto en la línea

 console.log("v: " + vArray[1]);

pero es como si no estuviera asignado al valor 1 en la línea

 value1 = vArray [1];

o al menos el valor se pierde después de salir del método Autenticar. ¿Cómo puede devolver ese valor a donde se realiza la llamada a createSpreadsheetEntry?

Gracias por adelantado. Guillermo.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!