Calvin Gaunce
Calvin Gaunce

Reputation: 366

Returning 'Range' instead of actual string in Google Apps Script

I am using the following function to return a concatenated string in Google Sheets. In this instance, B4 equals 'cardiology' and B1 equals '82-01'.

The expected result is dimension2=~cardiology;ga:eventCategory=~MS82-01.

However, I am getting this result, dimension2=~Range;ga:eventCategory=~MSRange.

Why is the function returning 'Range' instead of the actual strings?

function highLevelData() {
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); // get the spreadsheet object
  SpreadsheetApp.setActiveSheet(spreadsheet.getSheets()[1]); // set the first sheet as active
  var sheet = spreadsheet.getActiveSheet(); // get the active sheet
  var reportConfig = spreadsheet.getSheets()[0]; // set report configuration sheet
  var targetSpecialty = sheet.getRange("B4"); // get target specialty
  var specialtyDimension = "dimension2=~"; // set the sytanx string for the specialty dimension
  var targetCase = sheet.getRange("B1"); // get case
  var eventCategoryDimension = ";ga:eventCategory=~MS"; // set the syntax string for the event category dimension
  var filterOutput = specialtyDimension + targetSpecialty + eventCategoryDimension + targetCase; // concatenate full filter string
  var filterCell = reportConfig.getRange("B11"); // set the filter cell

  filterCell.setValue(filterOutput); // output filter string to filter cell

}

Upvotes: 2

Views: 5316

Answers (1)

Cameron Roberts
Cameron Roberts

Reputation: 7367

The "getRange()" functions return a Range object which represents cell(s) in the sheet.

To get the contents of the cell, call ".getValue()" on the Range object.

var targetSpecialty = sheet.getRange("B4").getValue();

See: https://developers.google.com/apps-script/reference/spreadsheet/range

Upvotes: 3

Related Questions