Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7079247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:38:54+00:00 2026-05-28T06:38:54+00:00

When I do the following: for (var CurrentRow=0;CurrentRow < qryMfg.RecordCount;CurrentRow++){ console.log(qryMfg.MFGID[CurrentRow]); dbo.transaction(function(myTrans) { console.log(qryMfg.MFGID[CurrentRow]);

  • 0

When I do the following:

for (var CurrentRow=0;CurrentRow < qryMfg.RecordCount;CurrentRow++){
    console.log(qryMfg.MFGID[CurrentRow]);
    dbo.transaction(function(myTrans) {
        console.log(qryMfg.MFGID[CurrentRow]);
    });
}

I get a list of MfgID the way that I want, followed by a list of unknowns because dbo.transaction is executing asynchronously.

How do I pass a variable into dbo.transaction?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:38:55+00:00Added an answer on May 28, 2026 at 6:38 am

    Variable scope is created in functions, so create a function that returns the handler…

    function create_handler( scoped_row ) {
        return function(myTrans) {
            console.log(qryMfg.MFGID[scoped_row]);
        };
    }
    

    …and invoke it in the loop, passing it whatever you need scoped, in this case, the CurrentRow…

    for (var CurrentRow=0;CurrentRow < qryMfg.RecordCount;CurrentRow++) {
        console.log(qryMfg.MFGID[CurrentRow]);
        dbo.transaction( create_handler(CurrentRow) );
    }
    

    Now each individual handler is created in the same unique scope that was created via the invocation in each iteration.

    Since the CurrentRow was passed into that function scope, each handler will reference the unique value in its own scope via the scoped_row parameter.

    When the handler is returned from the function, it will be passed to the dbo.transaction.

    Even though it is passed out of the function where it was created, it will retain its original variable scope, and so will always have access to the scoped_row parameter.


    You could also put the whole operation in the function if you prefer.

    function create_transaction( scoped_row ) {
        console.log(qryMfg.MFGID[scoped_row]);
    
        dbo.transaction( function(myTrans) {
            console.log(qryMfg.MFGID[scoped_row]);
        });
    }
    

    …which will have the same outcome as long as you pass it the CurrentRow…

    for (var CurrentRow=0;CurrentRow < qryMfg.RecordCount;CurrentRow++) {
        create_transaction( CurrentRow );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following var l = console.log.bind(console); l(-0); // 0 l(0); // 0 l(0
If I have the following var url = this.data; $.get(url, {}, function(data){ alert(data); });
I have the following function: var emptyFields = false; function checkNotEmpty(tblName, columns, className){ emptyFields
Having the following: var categories = new List<double> {10,20,30,40}; // Note the 40 here...
I have the following: var X = $('p:first'); $(X).each(function(index,Element) { tbody = ''; tr
Using the following: var date = new Date(parseInt(jsonDate.substr(6))); I get: Mon Feb 22 1993
I have the following: var Save = $('th:first')[0]; $('th').click(function() { if (Save !== this)
I have the following: var parsed_contacts = jQuery.parseJSON(conts); $('#contacts > li > a').click(function(event){ target_id
So I have the following: var change_handler = function(element) { // ... do some
I have the following knockout.js code I’ve got the following: var itemLine = function()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.