0

I've written a script within one of my google sheets that when a button is clicked it copies data from the active sheet and pastes it into another file. When logged in to any google account the script runs great but when anonymous users click the button nothing happens. According to the information regarding container-bound scripts, their permissions mirror the permissions of the container. I've insured that the container is shared for editing with anonymous users but the script still won't execute unless logged in.

What am I doing wrong? Code below.

function DataCapture() {


    // Set Sheets

    var source_sheet = SpreadsheetApp.getActiveSpreadsheet();
    var target = SpreadsheetApp.openById("0AtYhRMASIGlFdGVQWFprMEpOOFRrUGYxTmNGd0dZLVE");
    var target_sheet = target.getSheetByName('Data');

    // Get target last row
    var last_row = target_sheet.getLastRow();

    // Set Ranges
    var source_range = source_sheet.getRange("A2:P2");
    var target_range = target_sheet.getRange("A"+(last_row+1)+":P"+(last_row+1));
    var info_range = source_sheet.getRange("D7:E7");
    var dollar_range = source_sheet.getRange("B7:B8");
    var approver_range = source_sheet.getRange("D7:F7");

    // Fetch values
    var values = source_range.getValues();

    // Save to spreadsheet
    target_range.setValues(values);

    // Clear the fields for the next entry
    source_range.clearContent()
    info_range.clearContent()
    dollar_range.clearContent()
    approver_range.clearContent()

}
Mogsdad
  • 44,709
  • 21
  • 151
  • 275
  • It's usually a good idea to post your code, or, better yet, post just the chunk of code that's giving you difficulty. – user1618143 Aug 16 '13 at 21:33
  • Good point! Thank you and done! – user2690749 Aug 16 '13 at 22:18
  • By "press a button", do you mean that you have a drawing or image in the spreadsheet with a link to a script function? If so, have you tried focusing just on making sure the button works for anonymous users? ie with a bare-bones script that just does Browser.msgBox(). // Does your _script_ (not just this function) contain any calls to services that require user authentication, such as GmailApp? I've noticed that can cause problems in some cases. – Mogsdad Aug 23 '13 at 19:56

1 Answers1

1

The button will run under the users permission. If its anonymous it wont run if it needs any api permission (like reading the spreadsheet) since there is no user. For non anonymous users, you need to add a menu item that will trigger the google permission dialog (just do any dumb api call from it). After the user approves it will be able to click the image button

Zig Mandel
  • 19,571
  • 5
  • 26
  • 36