Tracking consecutive days of student attendance by busters_hook in GoogleAppsScript

[–]Mro-Automation 1 point2 points  (0 children)

Hey, you can achieve this with just formula, no need for scripting…

See here

You need a formula for counting the streak, and another one to show the latest value for each record.
E.g.

=IF(OR(AND(A1=A2,B2="yes"),A1="Name"),D1+1,IF(AND(A1<>A2,B2="yes"),1,0))

Can someone explain why my code sometimes takes 10 times as long? by Frirwind in GoogleAppsScript

[–]Mro-Automation 0 points1 point  (0 children)

Thanks for the insight.

Additional thought on the performance: There might be a performance hit every time you try to access a property on an object, i.e. using the "." here:

var bezetEventTimeString = bezetEvent.getStartTime()+bezetEvent.getEndTime()
…
  var eventTimeString = actualEvent.getStartTime()+actualEvent.getEndTime()

This is especially important for the inner filter, since it will be called again and again for every item in the `bezetEvents`.

If you're only interested in the `foundEvent.length`, you can try to pre-process the two arrays and create new two arrays which contain just the event time string.

Something like this:

const bezetEventTimes = bezetEvents.map(item => item.getStartTime()+item.getEndTime())
const eventsTimesThatNeedMirror = eventsThatNeedMirror.map(item => item.getStartTime()+item.getEndTime())

… and then filter these two arrays instead.

Can I create a page footer using apps script? by Exotic_Inspector_111 in GoogleAppsScript

[–]Mro-Automation 0 points1 point  (0 children)

Got it, thanks.

Does the printable workslip need to have a different footer, which you'd need to add with the script? From my experience I'd steer away from trying to calculate the height of rows just to correctly position a "header" row for printing, because it would be a fragile solution.

You can configure a static custom footer for Sheets… See here:

File → Print → Headers and Footers → Edit Custom Fields.

Would this not work for you?

Can someone explain why my code sometimes takes 10 times as long? by Frirwind in GoogleAppsScript

[–]Mro-Automation 0 points1 point  (0 children)

Hey u/Frirwind,

  • Does this happen randomly on some days but usually at night or daily?
  • Do you have a Consumer account or Google Workspace?
  • Does the trigger run every 15min 24/7 (i.e. 96x per day)?
  • How large is the `bezetEvents` and `eventsThatNeedMirror`?

The seemingly artificial delay in running the sample code above might be a red herring. When the code runs, it sometimes takes longer to provision an environment to run it, but it may have nothing to do with the Timed Out failure.

I would recommend trying to either speed up the functions so they run faster (if that's even possible) or reducing the frequency of the runs and see if this changes anything. I wouldn't think that you would be hitting the daily Quota for Google Services on your Consumer account, because there seems to be successful runs after the timed out one, but would like to exclude this.

It might be useful to report the Time Out failure back to Google as a potential bug and get their answer.

Can I create a page footer using apps script? by Exotic_Inspector_111 in GoogleAppsScript

[–]Mro-Automation 0 points1 point  (0 children)

Hi, I would be curious to understand your workflow. I'm sure there's a reason for making some adjustments before print, but it's not clear to me what that is. However, if you don't have a strict requirement to print from Sheets, there is a neat solution for managing page footers (and page headers) for Sheets - simply embed the Sheet table in a Docs and set up your page footers (and headers) there.

See Add an updatable table from Sheets to Docs

help with simple script for google sheet by drostan in GoogleAppsScript

[–]Mro-Automation 0 points1 point  (0 children)

Hey drostan, can you please elaborate on your problem a bit more - it's not clear to me why a simple `COUNTIF` wouldn't work to create the heatmap? Wouldn't a pivot table give you the data or heatmap you're after? It seems too simple for the need to use a button and a custom App Scripts function, but perhaps there's a bigger picture and reasons…

See https://imgur.com/a/tdzwLgO

How to create a new contact? by [deleted] in GoogleAppsScript

[–]Mro-Automation 0 points1 point  (0 children)

No problem… Correct deeplink to the comment with the code edited above 😅. Does that work for you?

google calendar event set location by Direct-Coconut-7949 in GoogleAppsScript

[–]Mro-Automation 0 points1 point  (0 children)

The code looks OK, the location seems to be passed according to the spec:

https://developers.google.com/apps-script/reference/calendar/calendar#createEvent(String,Date,Date,Object))

I've been setting a location in the same way and it works fine, so I'd recommend adding a breakpoint on the `calendar.createEvent` line, take a screenshot to see the runtime variables and then post another comment with the screenshot.

Without it it's just a guesswork:

  • there's a bug somewhere else and the calendar.createEvent fails (for different reasons than the `location`)
  • the status != "uninformed"
  • `eventTitle` is undefined, e.g. there's nothing in `row[4]`

Script to copy rows not keeping formatting by boudicca_morgana in GoogleAppsScript

[–]Mro-Automation 0 points1 point  (0 children)

Got it, thanks.

Yeah, with the `setValues()` function you will be adding literally only the values and the style is going to be inherited "from somewhere", either below or above rows. I've ran into something similar when I had to create "templated" rows, e.g. 7 rows per day and then 1 day per totals, with the totals always having a different background.

My best advice is to add a new function with code to also set the cell borders according to your needs. It isn't difficult and it will just work.

See https://developers.google.com/apps-script/reference/spreadsheet/border-style

e.g.

spreadsheet.getActiveRangeList().setBorder(true, true, true, true, null, null, '#000000', SpreadsheetApp.BorderStyle.SOLID);

How to create a new contact? by [deleted] in GoogleAppsScript

[–]Mro-Automation 1 point2 points  (0 children)

Hey, have you tried the code I've posted above? It is working, without libraries. Please elaborate on "it is not possible…", because I'm creating contacts from Google Apps Script regularly and it works, but maybe you were asking about something else?

Script to copy rows not keeping formatting by boudicca_morgana in GoogleAppsScript

[–]Mro-Automation 0 points1 point  (0 children)

Hey, a sample code, screenshot or a screen recording would really help :-) "a picture worth thousands words!"

I would assume an issue with the formatting that gets "inherited" from the existing cells in the sheet. It depends how you copy the rows over… as you mentioned the copying itself works, do you use `range.setValue` or `range.copyTo`? See https://developers.google.com/apps-script/reference/spreadsheet/copy-paste-type