0
function getCurrentId ()  {
    var data;
    var query = "INSERT INTO photos (path) VALUES (''); SELECT SCOPE_IDENTITY() AS id ";
    var request = new mssql.Request(connection);
    return new Promise(function(resolve, reject) {
        request.query(query, function(err, data) {
             resolve(data.recordset)
        });
    })
}

var main = async () =>{
    var quote =  await  getCurrentId();
    return quote; enter code here
};

I want to return value, not print.

Sterling Archer
  • 22,070
  • 18
  • 81
  • 118
  • You can't directly return an asynchronous value. You must return a promise or communicate back the return value via a callback. Your function returns long before the asynchronous value is available so there's no way in Javascript to return it. – jfriend00 Mar 22 '18 at 16:08
  • but my main aim to return data.recordset, I returned promice,but i can not return data.recordset – Дмитрий Литвин Mar 22 '18 at 16:14
  • You return the promise and you use `.then()` on the promise to get the data. That's how asynchronous values are returned. You cannot return the data value directly. The function returns long before the asynchronous value is even there. That's why you use promises. – jfriend00 Mar 22 '18 at 16:17
  • and i don*t how to return this value – Дмитрий Литвин Mar 22 '18 at 16:17
  • `main().then(quote => { /* put code here to use quote */})` – jfriend00 Mar 22 '18 at 16:18
  • after getting this value I want to assign value some variable – Дмитрий Литвин Mar 22 '18 at 16:20
  • This is the LAST time I'm going to say this. You CAN'T. Put the code that uses this variable inside a `.then()` handler. Go read the answer that yours is marked a duplicate of. There is lots of explanation and options there. – jfriend00 Mar 22 '18 at 16:21

0 Answers0