appScript to concatinate and incriment Query from reference cells while data exisits. What am I missing?











up vote
0
down vote

favorite












I'm going to go bald scratching my head so I really need as much help as I can get please. Can I please also learn from you too rather than get a solution i don't understand.



I have an appScript which concatinates substrings and an incrimentation variable which together, result in a comprehensive query to parse transaction data for each 'chart of account' referenc-code's key words, and then outputs "coded' matching transactions accordingly.



I've tested the query by manually incrimenting and stacking on a separate WIP_Query sheet:



={QUERY(Transactions, "Select A, B, C, D, P, "&COA!$B21&" where D MATCHES 's?.?s?"&TEXTJOIN("s?.s?|",True,Indirect("AutoCodeKeys!"&COA!$C21&"2:"&COA!$C21))&"s?.?s?'LABEL "&COA!$B21&" 'CODE'",1);QUERY(Transactions, "Select A, B, C, D, P, "&COA!$B22&" where D MATCHES 's?.?s?"&TEXTJOIN("s?.s?|",True,Indirect("AutoCodeKeys!"&COA!$C22&"2:"&COA!$C22))&"s?.?s?'LABEL "&COA!$B22&" 'CODE'",1)}



(I've tested more stacked than posted above)



It works perfectly, but when I try the auto-incrimented appScript one I get:



"Error: In ARRAY_LITERAL, an Array Literal was missing values for one or more rows."



The auto query appears to read fine to me???? (I am going cross-eyed)






function incrimentingQuerystring() {

Logger.clear();

var app = SpreadsheetApp.getActive();
var targetSheet = app.getSheetByName("scriptedQuery");
var targetCell = targetSheet.getRange(2, 1);
var refSheet = app.getSheetByName("ref");
var query;

//buildQueryFromSubStrings:

var beginString = ("={"); // Only to be added to first iteration.
var s1 = refSheet.getRange(3, 9).getValue();
var s2 = refSheet.getRange(4, 9).getValue();
var s3 = refSheet.getRange(5, 9).getValue();
var s4 = refSheet.getRange(6, 9).getValue();
var s5 = refSheet.getRange(7, 9).getValue();
var endString = (";"); // To be deducted from last iteration *************HOW????????*****************

//Get Chart Of Account Reference Codes to Query:

var data = app.getSheetByName("COA").getDataRange().getValues();

//Incriment though each accont in Chart of Acconts Sheet.

for (var i = 6; i < data.length; i++) {

var queryIteration = (s1 + (i - 1) + s2 + (i - 1) + s3 + (i - 1) + s4 + (i - 1) + s5 + endString);

//Logger.log(queryIteration);

var thisIteration = (queryIteration + thisIteration);

//Logger.log(thisIteration);
}

//Logger.log(i);

//******My attempt at removing var endString****

var finalIteration = (s1 + ("5") + s2 + ("5") + s3 + ("5") + s4 + ("5") + s5 + "}");

//Logger.log(finalIteration) // This seems correct but is preceded by "undefined" when added to query below:

var query = (beginString + thisIteration + finalIteration); // results "undefined" being added prior to finalIteration.

//Logger.log(query); //Runs out of space to see error. Error can be seen in targetCell in spreadsheet.

targetCell.setValue(query);
}





LinkToSpreadSheet










share|improve this question


























    up vote
    0
    down vote

    favorite












    I'm going to go bald scratching my head so I really need as much help as I can get please. Can I please also learn from you too rather than get a solution i don't understand.



    I have an appScript which concatinates substrings and an incrimentation variable which together, result in a comprehensive query to parse transaction data for each 'chart of account' referenc-code's key words, and then outputs "coded' matching transactions accordingly.



    I've tested the query by manually incrimenting and stacking on a separate WIP_Query sheet:



    ={QUERY(Transactions, "Select A, B, C, D, P, "&COA!$B21&" where D MATCHES 's?.?s?"&TEXTJOIN("s?.s?|",True,Indirect("AutoCodeKeys!"&COA!$C21&"2:"&COA!$C21))&"s?.?s?'LABEL "&COA!$B21&" 'CODE'",1);QUERY(Transactions, "Select A, B, C, D, P, "&COA!$B22&" where D MATCHES 's?.?s?"&TEXTJOIN("s?.s?|",True,Indirect("AutoCodeKeys!"&COA!$C22&"2:"&COA!$C22))&"s?.?s?'LABEL "&COA!$B22&" 'CODE'",1)}



    (I've tested more stacked than posted above)



    It works perfectly, but when I try the auto-incrimented appScript one I get:



    "Error: In ARRAY_LITERAL, an Array Literal was missing values for one or more rows."



    The auto query appears to read fine to me???? (I am going cross-eyed)






    function incrimentingQuerystring() {

    Logger.clear();

    var app = SpreadsheetApp.getActive();
    var targetSheet = app.getSheetByName("scriptedQuery");
    var targetCell = targetSheet.getRange(2, 1);
    var refSheet = app.getSheetByName("ref");
    var query;

    //buildQueryFromSubStrings:

    var beginString = ("={"); // Only to be added to first iteration.
    var s1 = refSheet.getRange(3, 9).getValue();
    var s2 = refSheet.getRange(4, 9).getValue();
    var s3 = refSheet.getRange(5, 9).getValue();
    var s4 = refSheet.getRange(6, 9).getValue();
    var s5 = refSheet.getRange(7, 9).getValue();
    var endString = (";"); // To be deducted from last iteration *************HOW????????*****************

    //Get Chart Of Account Reference Codes to Query:

    var data = app.getSheetByName("COA").getDataRange().getValues();

    //Incriment though each accont in Chart of Acconts Sheet.

    for (var i = 6; i < data.length; i++) {

    var queryIteration = (s1 + (i - 1) + s2 + (i - 1) + s3 + (i - 1) + s4 + (i - 1) + s5 + endString);

    //Logger.log(queryIteration);

    var thisIteration = (queryIteration + thisIteration);

    //Logger.log(thisIteration);
    }

    //Logger.log(i);

    //******My attempt at removing var endString****

    var finalIteration = (s1 + ("5") + s2 + ("5") + s3 + ("5") + s4 + ("5") + s5 + "}");

    //Logger.log(finalIteration) // This seems correct but is preceded by "undefined" when added to query below:

    var query = (beginString + thisIteration + finalIteration); // results "undefined" being added prior to finalIteration.

    //Logger.log(query); //Runs out of space to see error. Error can be seen in targetCell in spreadsheet.

    targetCell.setValue(query);
    }





    LinkToSpreadSheet










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm going to go bald scratching my head so I really need as much help as I can get please. Can I please also learn from you too rather than get a solution i don't understand.



      I have an appScript which concatinates substrings and an incrimentation variable which together, result in a comprehensive query to parse transaction data for each 'chart of account' referenc-code's key words, and then outputs "coded' matching transactions accordingly.



      I've tested the query by manually incrimenting and stacking on a separate WIP_Query sheet:



      ={QUERY(Transactions, "Select A, B, C, D, P, "&COA!$B21&" where D MATCHES 's?.?s?"&TEXTJOIN("s?.s?|",True,Indirect("AutoCodeKeys!"&COA!$C21&"2:"&COA!$C21))&"s?.?s?'LABEL "&COA!$B21&" 'CODE'",1);QUERY(Transactions, "Select A, B, C, D, P, "&COA!$B22&" where D MATCHES 's?.?s?"&TEXTJOIN("s?.s?|",True,Indirect("AutoCodeKeys!"&COA!$C22&"2:"&COA!$C22))&"s?.?s?'LABEL "&COA!$B22&" 'CODE'",1)}



      (I've tested more stacked than posted above)



      It works perfectly, but when I try the auto-incrimented appScript one I get:



      "Error: In ARRAY_LITERAL, an Array Literal was missing values for one or more rows."



      The auto query appears to read fine to me???? (I am going cross-eyed)






      function incrimentingQuerystring() {

      Logger.clear();

      var app = SpreadsheetApp.getActive();
      var targetSheet = app.getSheetByName("scriptedQuery");
      var targetCell = targetSheet.getRange(2, 1);
      var refSheet = app.getSheetByName("ref");
      var query;

      //buildQueryFromSubStrings:

      var beginString = ("={"); // Only to be added to first iteration.
      var s1 = refSheet.getRange(3, 9).getValue();
      var s2 = refSheet.getRange(4, 9).getValue();
      var s3 = refSheet.getRange(5, 9).getValue();
      var s4 = refSheet.getRange(6, 9).getValue();
      var s5 = refSheet.getRange(7, 9).getValue();
      var endString = (";"); // To be deducted from last iteration *************HOW????????*****************

      //Get Chart Of Account Reference Codes to Query:

      var data = app.getSheetByName("COA").getDataRange().getValues();

      //Incriment though each accont in Chart of Acconts Sheet.

      for (var i = 6; i < data.length; i++) {

      var queryIteration = (s1 + (i - 1) + s2 + (i - 1) + s3 + (i - 1) + s4 + (i - 1) + s5 + endString);

      //Logger.log(queryIteration);

      var thisIteration = (queryIteration + thisIteration);

      //Logger.log(thisIteration);
      }

      //Logger.log(i);

      //******My attempt at removing var endString****

      var finalIteration = (s1 + ("5") + s2 + ("5") + s3 + ("5") + s4 + ("5") + s5 + "}");

      //Logger.log(finalIteration) // This seems correct but is preceded by "undefined" when added to query below:

      var query = (beginString + thisIteration + finalIteration); // results "undefined" being added prior to finalIteration.

      //Logger.log(query); //Runs out of space to see error. Error can be seen in targetCell in spreadsheet.

      targetCell.setValue(query);
      }





      LinkToSpreadSheet










      share|improve this question













      I'm going to go bald scratching my head so I really need as much help as I can get please. Can I please also learn from you too rather than get a solution i don't understand.



      I have an appScript which concatinates substrings and an incrimentation variable which together, result in a comprehensive query to parse transaction data for each 'chart of account' referenc-code's key words, and then outputs "coded' matching transactions accordingly.



      I've tested the query by manually incrimenting and stacking on a separate WIP_Query sheet:



      ={QUERY(Transactions, "Select A, B, C, D, P, "&COA!$B21&" where D MATCHES 's?.?s?"&TEXTJOIN("s?.s?|",True,Indirect("AutoCodeKeys!"&COA!$C21&"2:"&COA!$C21))&"s?.?s?'LABEL "&COA!$B21&" 'CODE'",1);QUERY(Transactions, "Select A, B, C, D, P, "&COA!$B22&" where D MATCHES 's?.?s?"&TEXTJOIN("s?.s?|",True,Indirect("AutoCodeKeys!"&COA!$C22&"2:"&COA!$C22))&"s?.?s?'LABEL "&COA!$B22&" 'CODE'",1)}



      (I've tested more stacked than posted above)



      It works perfectly, but when I try the auto-incrimented appScript one I get:



      "Error: In ARRAY_LITERAL, an Array Literal was missing values for one or more rows."



      The auto query appears to read fine to me???? (I am going cross-eyed)






      function incrimentingQuerystring() {

      Logger.clear();

      var app = SpreadsheetApp.getActive();
      var targetSheet = app.getSheetByName("scriptedQuery");
      var targetCell = targetSheet.getRange(2, 1);
      var refSheet = app.getSheetByName("ref");
      var query;

      //buildQueryFromSubStrings:

      var beginString = ("={"); // Only to be added to first iteration.
      var s1 = refSheet.getRange(3, 9).getValue();
      var s2 = refSheet.getRange(4, 9).getValue();
      var s3 = refSheet.getRange(5, 9).getValue();
      var s4 = refSheet.getRange(6, 9).getValue();
      var s5 = refSheet.getRange(7, 9).getValue();
      var endString = (";"); // To be deducted from last iteration *************HOW????????*****************

      //Get Chart Of Account Reference Codes to Query:

      var data = app.getSheetByName("COA").getDataRange().getValues();

      //Incriment though each accont in Chart of Acconts Sheet.

      for (var i = 6; i < data.length; i++) {

      var queryIteration = (s1 + (i - 1) + s2 + (i - 1) + s3 + (i - 1) + s4 + (i - 1) + s5 + endString);

      //Logger.log(queryIteration);

      var thisIteration = (queryIteration + thisIteration);

      //Logger.log(thisIteration);
      }

      //Logger.log(i);

      //******My attempt at removing var endString****

      var finalIteration = (s1 + ("5") + s2 + ("5") + s3 + ("5") + s4 + ("5") + s5 + "}");

      //Logger.log(finalIteration) // This seems correct but is preceded by "undefined" when added to query below:

      var query = (beginString + thisIteration + finalIteration); // results "undefined" being added prior to finalIteration.

      //Logger.log(query); //Runs out of space to see error. Error can be seen in targetCell in spreadsheet.

      targetCell.setValue(query);
      }





      LinkToSpreadSheet






      function incrimentingQuerystring() {

      Logger.clear();

      var app = SpreadsheetApp.getActive();
      var targetSheet = app.getSheetByName("scriptedQuery");
      var targetCell = targetSheet.getRange(2, 1);
      var refSheet = app.getSheetByName("ref");
      var query;

      //buildQueryFromSubStrings:

      var beginString = ("={"); // Only to be added to first iteration.
      var s1 = refSheet.getRange(3, 9).getValue();
      var s2 = refSheet.getRange(4, 9).getValue();
      var s3 = refSheet.getRange(5, 9).getValue();
      var s4 = refSheet.getRange(6, 9).getValue();
      var s5 = refSheet.getRange(7, 9).getValue();
      var endString = (";"); // To be deducted from last iteration *************HOW????????*****************

      //Get Chart Of Account Reference Codes to Query:

      var data = app.getSheetByName("COA").getDataRange().getValues();

      //Incriment though each accont in Chart of Acconts Sheet.

      for (var i = 6; i < data.length; i++) {

      var queryIteration = (s1 + (i - 1) + s2 + (i - 1) + s3 + (i - 1) + s4 + (i - 1) + s5 + endString);

      //Logger.log(queryIteration);

      var thisIteration = (queryIteration + thisIteration);

      //Logger.log(thisIteration);
      }

      //Logger.log(i);

      //******My attempt at removing var endString****

      var finalIteration = (s1 + ("5") + s2 + ("5") + s3 + ("5") + s4 + ("5") + s5 + "}");

      //Logger.log(finalIteration) // This seems correct but is preceded by "undefined" when added to query below:

      var query = (beginString + thisIteration + finalIteration); // results "undefined" being added prior to finalIteration.

      //Logger.log(query); //Runs out of space to see error. Error can be seen in targetCell in spreadsheet.

      targetCell.setValue(query);
      }





      function incrimentingQuerystring() {

      Logger.clear();

      var app = SpreadsheetApp.getActive();
      var targetSheet = app.getSheetByName("scriptedQuery");
      var targetCell = targetSheet.getRange(2, 1);
      var refSheet = app.getSheetByName("ref");
      var query;

      //buildQueryFromSubStrings:

      var beginString = ("={"); // Only to be added to first iteration.
      var s1 = refSheet.getRange(3, 9).getValue();
      var s2 = refSheet.getRange(4, 9).getValue();
      var s3 = refSheet.getRange(5, 9).getValue();
      var s4 = refSheet.getRange(6, 9).getValue();
      var s5 = refSheet.getRange(7, 9).getValue();
      var endString = (";"); // To be deducted from last iteration *************HOW????????*****************

      //Get Chart Of Account Reference Codes to Query:

      var data = app.getSheetByName("COA").getDataRange().getValues();

      //Incriment though each accont in Chart of Acconts Sheet.

      for (var i = 6; i < data.length; i++) {

      var queryIteration = (s1 + (i - 1) + s2 + (i - 1) + s3 + (i - 1) + s4 + (i - 1) + s5 + endString);

      //Logger.log(queryIteration);

      var thisIteration = (queryIteration + thisIteration);

      //Logger.log(thisIteration);
      }

      //Logger.log(i);

      //******My attempt at removing var endString****

      var finalIteration = (s1 + ("5") + s2 + ("5") + s3 + ("5") + s4 + ("5") + s5 + "}");

      //Logger.log(finalIteration) // This seems correct but is preceded by "undefined" when added to query below:

      var query = (beginString + thisIteration + finalIteration); // results "undefined" being added prior to finalIteration.

      //Logger.log(query); //Runs out of space to see error. Error can be seen in targetCell in spreadsheet.

      targetCell.setValue(query);
      }






      google-apps-script google-sheets-query






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 18 hours ago









      user252391

      83




      83





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371098%2fappscript-to-concatinate-and-incriment-query-from-reference-cells-while-data-exi%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371098%2fappscript-to-concatinate-and-incriment-query-from-reference-cells-while-data-exi%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Wiesbaden

          Marschland

          Dieringhausen