7
votes

I keep getting this error

"ReferenceError: "BigQuery" is not defined. (line 19, file "Code")"

when trying to this script in apps script

function saveQueryToTable() {
  var projectId = 'fiery-cabinet-****';
  var datasetId = '11234***1';
  var tableId = 'TEST4';
  var job = {
    configuration: {
      query: {
        query: 'SELECT *' +
               'FROM Test2;',
        destinationTable: {
          projectId: projectId,
          datasetId: datasetId,
          tableId: tableId
        }
      }
    }
  };

  var queryResults = BigQuery.Jobs.insert(job, projectId);
  Logger.log(queryResults.status);
}

Could anyone let me know where I'm going wrong?

Thanks

2

2 Answers

12
votes

You need to enable the BigQuery service.

  1. Resources > Advanced Google Services
  2. Enable BigQuery

enter image description here

-1
votes

If you are under Google Apps Script UI, you can reach the "Advanced Google Services" under Resources.

Happy coding!