Automatic update in google scripts while using google spreadsheets

By Maddi

I am new to script
my task is to update staff names in menu so that when someone choose their name they can see their clients and their details.
I have a problem with automatically update the menu I appreciate any help.

uniqueValues functions is searching through my sheet and finding the unique staff names which is work.

my menu codes which doesn’t work is owner function
my code is as follows:

function owner() {
 var ui = SpreadsheetApp.getUi();
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet =ss.getSheetByName("sheet1")
  var menu = ui.createMenu('Owners Name:')
   subMenu = ui.createMenu('Go to owners clients');
  var menuEntries = []
  var menuEntries = uniqueValues();
  for (i=0; i < menuEntries.length; i++){
      menuEntries.push({ name: menuEntries[i], functionName: "OwnerSelection"+i });
      subMenu.addItem(menuEntries, "OwnerSelection"+i); // You have to change this to sheets[i].getName()
  subMenu = ui.createMenu('Go to Owners clients');
function uniqueValues(){
  var col = 1 ; // choose the column you want to use as data source (0 indexed, it works at array level)
  var source = SpreadsheetApp.openById('1O5wGrxGKJBKdxM1Mrax5TpjMNkys0fAtAjxlw');
  var sheet = source.getSheetByName('TRACKER')
  var source = SpreadsheetApp.getActiveSheet();
  var source = SpreadsheetApp.getActiveSpreadsheet();
  var data=sheet.getDataRange().getValues();// get all data
  var data=sheet.getDataRange().getValues();
  var newdata = new Array();
  for(nn in data){
    var duplicate = false;
    for(j in newdata){
      if(data[nn][col] == newdata[j][0]){
        duplicate = true;
  return newdata;

Source: Stack Overflow


Share it with your friends!

    Fatal error: Uncaught Exception: 12: REST API is deprecated for versions v2.1 and higher (12) thrown in /home/content/19/9652219/html/wp-content/plugins/seo-facebook-comments/facebook/base_facebook.php on line 1273