We use a master spreadsheet containing all the information of the students. I want to create a UI to capture the marks of each student and write it to a Google Sheet from which I will generate their report cards.
I use the following code to import the data from the master list - the names gets imported correctly, but I cannot seem to pull the values? I just get "undefined"
/**
 * A function that inserts a custom menu when the spreadsheet opens to generate the Report Spreadsheet.
 */
function onOpen() {
  var menu = [{name: 'Capture Report Data', functionName: 'setUpProgressReport_'}];
  SpreadsheetApp.getActive().addMenu('Progress Report', menu);
}
/**
 * A set-up function that creates a Report Sheet based on the class selected
 */
function setUpProgressReport_() {
  var ss = SpreadsheetApp.getActive();
  var sheet = ss.getSheetByName('Report 1');
  var ui = SpreadsheetApp.getUi(),
  response = ui.prompt(
    'Enter Class',
    'Please enter the class you would like to enter marks for',
    ui.ButtonSet.OK_CANCEL),
  selectedClass = response.getResponseText();
  //Import names of learners by selected class from Master Sheet
  var cell = sheet.getRange("A1");
  cell.setFormula('=QUERY(IMPORTRANGE("1Dxjt6W54e7n2F8a2zlRZV0n-VtCoPZTC2oZgeMPd8mE","MasterList!A1:Z2000"),"SELECT Col1, Col2,Col4 WHERE Col4 contains ' + "'" + selectedClass + "'" + ' Order by Col2 asc")');
  // Freezes the first row to be used as headings
  sheet.setFrozenRows(1);
  var lastRow = sheet.getLastRow();
  var lastColumn = sheet.getLastColumn();
  var values = SpreadsheetApp.getActiveSheet().getRange(lastRow, lastColumn).getValues();
  Browser.msgBox(values[0][22]);
}