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
google-apps-script google-sheets-query
add a comment |
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
google-apps-script google-sheets-query
add a comment |
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
google-apps-script google-sheets-query
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
google-apps-script google-sheets-query
asked 18 hours ago
user252391
83
83
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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