1

I am using mssql in node.js executing an SP:

var fnGetMapping = function(results) {

        new sql.Request(db.sqlConnection)
            .input('myParam', sql.VarChar(60), 'myValue')
            .execute('usp_MySP', fnProcessUUIDData);
};

Now my fnProcessUUIDData looks like this:

var fnProcessUUIDData = function(err, recordsets) {
    if (err) {
        console.log("Error calling MS SQL: " + err.message);
    } else {
        if (recordsets[0].length > 0) {

        } else {

        };
    }
};

What I need now is to pass one of my own parameter into fnProcessUUIDData.

I read some articles that this is possible but I couldn't get it working on my case, would appreciate some comments if what I want to do is possible.

2 Answers 2

3

You can use apply to pass some extra arguments without loosing the context.

new sql.Request(db.sqlConnection)
  .input('myParam', sql.VarChar(60), 'myValue')
  .execute('usp_MySP', function(...args) {
    fnProcessUUIDData.apply(this, args.concat(some, extra, parameters));
  });

var fnProcessUUIDData = function(err, recordsets, some, extra, parameters) {
  console.log(this, some, extra, parameters);
};
Sign up to request clarification or add additional context in comments.

Comments

2

Using apply overcomplicates things because fnProcessUUIDData is a plain old function and not a method (it doesn't use this internally). All you need to do is wrap it in another function:

new sql.Request(db.sqlConnection)
  .input('myParam', sql.VarChar(60), 'myValue')
  .execute('usp_MySP', function(err, recordsets) {
    fnProcessUUIDData(err, recordsets, additional_parameter);
  });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.