Containerized google script fails even after container has been split

I wrote a script in one of my google sheets that when a button is clicked, it copies the data from the active sheet and pastes it into another file. When logged into google account the script works fine, but when anonymous users click the button nothing happens. According to the information on scripts related to containers, their permissions reflect the container's permissions. I have insured that the container is being used for editing by anonymous users, but the script still won't execute unless it is logged in.

What am I doing wrong? The code is 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()

}

      

0


source to share


1 answer


The button runs under user rights. If its anonymous it won't start if it needs any api permission (like reading spreadsheet) as there is no user. For non-anonymous users, you need to add a menu item that will bring up the google permission dialog (just make some dumb api call from it). After the user approves, they can click the image button



+1


source







All Articles