0

Anyone know why this caused The script does not have permission to get the active user's identity.?

I don't have any functions that asks for the user identity. So I'm a little confused.

function onEdit(e) {

    if (e.range.getA1Notation() == 'D5' || e.range.getA1Notation() == 'E5' || e.range.getA1Notation() == 'F5') {

        var range = e.range;
      var now = new Date();
        var time1 = Utilities.formatDate(new Date(now.getTime()), "GMT-8","E M/d/yy h:mm:ss a");
        range.setNote('Please wait 15 sec for total calculation in Notes to complete.' + String.fromCharCode(10) + String.fromCharCode(10) + 'Last modified: '  + String.fromCharCode(10) + time1 + ' PST');

        var sheetUS = SpreadsheetApp.getActive().getSheetByName('US');
        var principle = range.getValues();
        var rownum = sheetUS.getRange("N1").getValues();
        var term = sheetUS.getRange("C7:C" + rownum).getValues();

        if (e.range.getA1Notation() == 'D5') {
            var payment = sheetUS.getRange("D7:D" + rownum).getValues();
            for (var i = 0; i < term.length; i++) {
                var total = term[i] * payment[i];
                var totalinterest = term[i] * payment[i] - principle;
                sheetUS.getRange(i + 7, 4).setNote(
                  'Total Loan Interest: $' + comma(totalinterest.toFixed(2)) + String.fromCharCode(10) + String.fromCharCode(10) +
                  'Total Payment: $' + comma(total.toFixed(2)) 
                );

            }
        } 
}
  • 1
    How are you calling this function? – Rubén Nov 23 '18 at 0:57
  • it is actually just onEdit, I just changed it to onEdit1 to disable it. Edited post. – sojim2 Nov 23 '18 at 7:25
0

The range the script tried to add notes was within a protected range. That's why it works for app owner but not shared editors. I just unprotected the range for the script and it worked. Not ideal but it gets the job done. Hopefully Google will have separate permission layers for notes and cells. (also notes should have formatting!)

0

The OP commented on an answer that the target range is protected.

The error occurred because onEdit simple triggers run anonymously. An installlable onEdit trigger runs withe the credentials of the user who created the trigger, so if they are allowed to edit the protected range, the script will be able to complete it's execution.

To solve the problem, change the name of function in order to avoid be ran by the simple trigger and create an installable trigger by using an account allowed to edit the protected range.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.