1

I have a program that works as below

function test() {
var urls = [
    'URL1, 
    'URL2',
    'URL3'
  ]

var results = xx(urls)

^and then xx works its magic and produces results.

Now I want to input the urls via a column in a spreadsheet instead of hard coding them into the script, and so I tried

 function test() {
    var urls = []
    var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Input")
    urls[0] = ss.getRange(2, 1, ss.getLastRow()-1,1).getValues().join()
    
    var results = xx(urls)

But the result is that only one of the URLs gets processed.

0

2 Answers 2

3

Explanation:

You haven't provided what this magical xx function does, but according to the first code snippet, xx accepts a single array of elements.

Therefore, one way of going from 2D array to 1D is to use flat

Solution:

function myFunction() {
  const ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Input")
  const urls = ss.getRange(2, 1, ss.getLastRow()-1).getValues().flat(); // 1D array
  const results = xx(urls);
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the reply! Unfortunately flat() doesn't seem to work with Google apps scripts?
@user10553622 enable v8 environment and it will work..... Google on how to enable v8 environment : developers.google.com/apps-script/guides/v8-runtime
0

Not sure this is the most elegant solution, but got it to work by modifying it:

function test() {
var urls = {}
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Input")
urls = ss.getRange(2, 1, ss.getLastRow()-1,1).getValues();
urls = [].concat.apply([], urls)

var results = xx(urls)

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.