I have a Spreadsheet where I have used IMPORTRANGE
to pull data from another spreadsheet. I also have a script that always gets the last row of specific columns, fills a form, create a link and send it to someone.
I'm trying to use getValues()
to get the value of a specific cell that has been filled with data from IMPORTRANGE
function.
function askForPrice() {
var ss = SpreadsheetApp.openById('xXx');
var sheet = ss.getSheetByName('Sheet1');
var range1 = ss.getRange('A1').getDataRegion().getLastRow();
var data = ss.getDataRange().getValues();
var formUrl = ss.getFormUrl();
var form = FormApp.openByUrl('xXxXx');
var items = form.getItems();
var dateCol = 1
var myID = sheet.getRange(range1, dateCol).getValue();
var dataCol1 = sheet.getRange(range1, dateCol).getValue();
Logger.log(dataCol1)
The problem is that after I run the code and use Logger.log()
to check what value is captured by getValues()
, nothing appears.
If the content is typed directly into the cell, I am able to return it through Logger.log()
. But if the cell is contained in the IMPORTRANGE
range, it doesn't appear in Logger.log()
.
What should I do to get this to work, so the value of the cell would be returned?
Get value of cell using IMPORTRANGE
formula.
Instead of using getValues()
, use getDisplayValues()
. This returns the displayed value of the cells in a 2d array.
Your line of code would look something like this:
var data = ss.getDataRange().getDisplayValues();