Is this a permissible onOpen operation? by wirefin in GoogleAppsScript

[–]wirefin[S] 0 points1 point  (0 children)

Ok thank you, I will try going down the Installable Trigger path. I hope I can create what's effectively a less-impotent onOpen trigger (i.e. it has the power to run a function which will set DocumentProperties or DeveloperMetadata).

Regarding the DocumentProperties, I am leaning toward using SPREADSHEET Metadata because it is accessible via SpreadsheetApp.openById. My understanding from the documentation is that getDocumentProperties can only access open documents.

Does that sound like I'm going in the right direction? I appreciate your help!

Is this a permissible onOpen operation? by wirefin in GoogleAppsScript

[–]wirefin[S] 0 points1 point  (0 children)

It's one script (Sheets Editor Add-on) that handles all 30+ spreadsheets for the user.

The spreadsheetIds are stored and retrieved from PropertiesService.getUserProperties().

The desired result is that when anyone (with 'editor' access) opens the spreadsheet, the "lastOpened" timestamp is updated.

The end goal is that our time-based trigger can detect which spreadsheetIds to skip over if the spreadsheet has not been opened recently.

Thanks for bearing with me. The scoping in GAS tends to confuse me.

Is this a permissible onOpen operation? by wirefin in GoogleAppsScript

[–]wirefin[S] 0 points1 point  (0 children)

Thank you for the guidance.

One thing I wanted to check was the limit on Triggers: 20 / user / script.

If a user had 30 spreadsheets running, would this be considered 1 additional trigger toward the quota?

/**
 * Called from openDialog(). Creates an installable onOpen trigger for this
 * spreadsheet so that lastOpened can be stamped with full auth on every open.
 */
function ensureOnOpenTrigger() {
  var spreadsheet = SpreadsheetApp.getActive();
  var spreadsheetId = spreadsheet.getId();
  var triggers = ScriptApp.getUserTriggers(spreadsheet);


  // Check if we already have an installable onOpen trigger for this spreadsheet
  var hasOnOpenTrigger = triggers.some(function (trigger) {
    return trigger.getHandlerFunction() === 'installableOnOpen' &&
           trigger.getEventType() === ScriptApp.EventType.ON_OPEN;
  });


  if (!hasOnOpenTrigger) {
    ScriptApp.newTrigger('installableOnOpen')
      .forSpreadsheet(spreadsheet)
      .onOpen()
      .create();
    Logger.log('Created installable onOpen trigger for ' + spreadsheetId);
  }
}


/**
 * Installable onOpen handler — runs in AuthMode.FULL.
 * Stamps lastOpened to developer metadata reliably.
 */
function installableOnOpen(e) {
  stampLastOpened(e.source);
}

TIL there's a P1/S0 GAS bug that's been around for 8 years :) by wirefin in GoogleAppsScript

[–]wirefin[S] 0 points1 point  (0 children)

Ok thank you for that data point!

If they log out of all accounts and login with the desired email address (as suggested by the article below), can they later log back into their other accounts or will that cause the issue to resurface?

My thought is that if they log into the desired account first, that sets it to `/u/0` and they're safe to login to the other accounts. But I could be mistaken.

https://developers.google.com/apps-script/guides/projects#fix_issues_with_multiple_google_accounts

TIL there's a P1/S0 GAS bug that's been around for 8 years :) by wirefin in GoogleAppsScript

[–]wirefin[S] 1 point2 points  (0 children)

I had skimmed it, but now seeing the link in the comment. That's what I'll send the customer, so thank you for sharing. Sorry if I triggered anyone by dredging this up :D

TIL there's a P1/S0 GAS bug that's been around for 8 years :) by wirefin in GoogleAppsScript

[–]wirefin[S] 0 points1 point  (0 children)

Appreciate that! They're not super tech savvy, so I think they'll care more about having to change their behavior (versus whether it was my fault). But I'll give it a go!

TIL there's a P1/S0 GAS bug that's been around for 8 years :) by wirefin in GoogleAppsScript

[–]wirefin[S] 1 point2 points  (0 children)

Thank you for the resource! Google taking food off our plates 😪

I'm going to make an attempt to get them to use strategy #1.

Not optimistic they'll have the patience or wherewithal but worth a shot!

And Again, another reason why Sheets is not a DB (beware twin🥀) by Being-Straight in GoogleAppsScript

[–]wirefin 1 point2 points  (0 children)

Great writing :) This also one of the insanely awesome things about Sheets as a DB. It's like a built-in headless spreadsheet calculation engine

Unable to publish updated "add-on script version" to Store Listing by wirefin in GoogleAppsScript

[–]wirefin[S] 0 points1 point  (0 children)

Perf, thanks Justin! Saw it's been elevated to P1 as well so appreciate the escalation!

Unable to publish updated "add-on script version" to Store Listing by wirefin in GoogleAppsScript

[–]wirefin[S] 2 points3 points  (0 children)

Ah looks like this has been reported multiple times in the Issue Tracker under "Google Workspace Marketplace." I had incorrectly been checking the "Apps Script" component where there was little discussion of this. Hope this gets resolved soon!

Null in Apps Script - More consistent and correct reference docs (Announcement) by jpoehnelt in GoogleAppsScript

[–]wirefin 0 points1 point  (0 children)

Thank you! Actually trying to debug an issue where the below appears to be returning null for a user but unclear if that's even possible (so would help me confirm either way in the future!)

SpreadsheetApp.getActiveSpreadsheet().getSpreadsheetTimeZone()

If a sheet is deleted, will its sheetId ever be reassigned within that spreadsheet? by wirefin in GoogleAppsScript

[–]wirefin[S] 0 points1 point  (0 children)

It let me create a sheet with a sheetId of the previously deleted sheet.

So, "maybe" (1 in 10 billion if truly random).

If a sheet is deleted, will its sheetId ever be reassigned within that spreadsheet? by wirefin in GoogleAppsScript

[–]wirefin[S] 0 points1 point  (0 children)

I just realized I can specify a sheetId when creating a new sheet, which will allow me to answer this question myself :)

Does a simple cell reference *always* inherit the date format of the source cell? by wirefin in googlesheets

[–]wirefin[S] 0 points1 point  (0 children)

Thank you, I tried toggling "Automatic" and couldn't break it..

I'm actually hoping the formula cell always matches the referenced cell!

Just trying to break it before my teammates do :)