1

I have been using the following custom Google Apps Script for years, and for some reason it has stopped working, partially. The script is supposed to retrieve an array of items, and then display them in a spreadsheet column. Here is the script:

function myAccounts() {
    var output = [], arr = JSON.parse(createArr());  
    for(var i=0, iLen=arr.length; i<iLen; i++) {
        output.push([arr[i][0]]);
    }  
output = output.sort();  
return output;
}

By using the debugger, I am able to see that the array appears to be created properly. This is the output of the function:

var arr = [

[["5383 - CATEGORY A"],["ASSESSMENT REVIEW BRD","ANNUAL FEE", "ATG ASSESS REVIEW BOARD TORONTO ", "ATG-ASSESSMENT REVIEW BRD TORONTO ",
 "MPAC-PICKERING","CITIZENSHIP & IMM ON-LINEOTTAWA","JONES"]],

[["5230 - CATEGORY B"], ["RED CROSS","G(IRLS)20 SUMMIT","MOVEMBER    *CHARITY","HOSP FOR SICK CHILDREN","URBAN SQUASH TORONTO"]],

[["5351 - CATEGORY C"], ["ELTE","PAYPAL *SMITH","PRAXIS INTERNATIONAL ART"]],

[["5350 - CATEGORY D"], ["PAYPAL *CANADAWIDEP","LA PARETE GALLERY","ACTIVE SURPLUS","PAYPAL *DHL EXPRESS","PRINT THREE #95","STAPLES.CA",
  "FRAMING FACTORY"]],

[["5387 - CATEGORY E"], ["SWEETSERVICES","EVENT RENTAL","GLOBAL FINANCIAL","IVISA SERVICES NORTH SYDNEY","QUEST HENDERSON",
 "SLS HOTEL BEVERLY HILLS","LITTLE TIKES","FAIRY FLOWER","FARICY PTY LTD","VISTAPRINT.AU","MYBAGSCOMPA","ITS MY PARTY","PAYPAL *CAMILLEPRIN"]]

]

For some reason, this output is not being seen in the cell of the spreadsheet which calls the function. It doesn't throw an error, but simply leaves the cell completely blank.

Any idea what might be going wrong? Thanks.

1 Answer 1

1

The output needs to be a value, an array or an array of arrays.
You have an array of array of arrays which Sheets doesn't know how to handle.
Try removing one level by having the output being

[["CATEGORY A"], ["CATEGORY B"], ["CATEGORY C"]]

This will return one row with three columns.
You can do that from what I can see in the code by writing output.push(arr[i][0]);.
I assume arr[i][0] is already a one element array. which is why this happens.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks @Robins. Your solution makes sense, but I think that I may not have asked the correct question. I may have oversimplified the structure of my actual data array. I have now edited the question to show my actual multi-dimensional array. As you can see from my data, the result that I am trying to return is the first level inside my array, CATEGORY A, CATEGORY B, ... etc. I am going to keep trying to figure it out based on your suggestion, but if you spot the problem I would appreciate if you could let me know. Thanks.
The same logic applies. Try output.push(arr[i][0]); and your output will be all the xxxx - category y in separate rows of the column the formula is in.
Thanks again @Robin. You nailed it. Changing this code from this: output.push([arr[i][0]]); to this: output.push(arr[i][0]); managed to solve the problem. I have no idea why this code seemingly worked fine for years with that extra set of square brackets, and suddenly it stopped working. Now thanks to your suggestion I have removed the extra square brackets and it is working fine again. Cheers.

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.