Home > other >  Script function could not be found even though script works in Google Apps Script
Script function could not be found even though script works in Google Apps Script

Time:12-02

I just started learning about Google Apps Scripts and I created this script that will help me copy a range of data in Google Sheets into another sheet.

This is my code

function copyPaste() 
{
  const ss = SpreadsheetApp.openById('1btVcMHU2a4hyU6gz3D4ZN7RYXX_HYWLKJPxuGmdKvEI').getSheetByName('Form1'); 
  const nutriSheet = SpreadsheetApp.openById('1btVcMHU2a4hyU6gz3D4ZN7RYXX_HYWLKJPxuGmdKvEI').getSheetByName('Data');
  const nutriLastRow = nutriSheet.getLastRow(); 

  let copyRange = ss.getSheetValues(3,7,1,30); 
  let rowValues = ss.getRange(3,7,1,30).getValues();

  nutriSheet.getRange(nutriLastRow 1, 2, 1, 30).setValues(rowValues);
}

The code works when I run it from the app but when I tried to assign the script to a button(drawing) and entering copyPaste, it says "Script function copyPaste could not be found".

I made sure to name it as the function and not the google app script project name.

I ahve also tried opening it in incognito but it still didn't work.

I was really happy to get the code to work but now I need to figure out how to run it from Google Sheet.

I have also tried to use the ui.createMenu('Custom Menu') but I can't seem to get it to work. It says "Cannot call SpreadsheetApp.getUi() from this context"

function onOpen(e) {
  let ui = SpreadsheetApp.getUi(); 
  ui.createMenu('           
  • Related