Same script working differently in 2 script editors - google-apps-script

Premise: I have not a problem with algorythms or syntax or method and so on, for this reason I apologize not to report scripts or piece of it.
But I am in a mistery.
I have a Form for booking medical appointments, filled on line by patients, that feeds a Sheet where appointments are reported. The sheet is used only by the doctor to have the view of his engagements. The form suggests to the patients a list of days and hourly slots, by a ListItem of open time intervals (i.e.: Wed March, 3 hh 11 - 11:20 am ). The sheet (triggered on submit of the form) drives the automatic update of the List Item of the Google Form, to be proposed to the next patient requiring an appointment.
One function in one script for all, it works perfectly.
Now, I would like to give the doctor the possibility to manage the table of the appointment (the sheet), editing the cells of the table itself. But so doing the List Item of the time slots in the Form has to be updated every time the table is edited (triggering on edit).
So, to the aim:
1) I took the piece of my script in charge of updating the Form, which became a new function in the same script editor as I developed the primary function. The new function works perfectly when it runs from the script editor of the Form.
2) I copy INTEGRALLY the above script in the script editor of the sheet and...a for loop does not work as expected, in any way it does not work as it does in the Form environment.
Note: every files are opened by ID and no methods are invoked on "active" file.
Thanks

Posting for documentation purposes; OP found the answer, as per their comment:
And I finally solved. It was a problem arising from the Timezone management. In facts, Guide says: "New scripts default to the owner's time zone, but the script's time zone can be changed by clicking File > Project properties in the script editor." I did, problem evaporated and I found my peace.

Related

How to implement? Spreadsheet with link - Go To Link Grab Data - Update Spreadsheet Row

I am looking for technology suggestions. Or if this can be done in native google sheets (note the site I am looking to access is behind a username and password).
I have a google sheet that looks like this
birth date
link
data_element_from_website
12/31
https://something.com/3920230
1/31
https://something.com/1920238
lets say on https://something.com/3920230 there is a HTML element 123
Twice a day I want to be able to refresh the data, this could be done by going into the spreadsheet and clicking/doing something.
Can this be done?
What if https://something.com/3920230 is behind a login (authentication). Note: I could be logged in to the website in a different tab... I don't think that would make a difference though...
Assuming you have a script that you would like to run twice a day, you can use Apps Script Time-driven triggers:
A time-driven trigger (also called a clock trigger) is similar to a cron job in Unix. Time-driven triggers let scripts execute at a particular time or on a recurring interval, as frequently as every minute or as infrequently as once per month. (Note that an add-on can use a time-driven trigger once per hour at most.)
If it's just some formulae, you can change the recalculation settings to be either On change, On change and every minute or On change and every hour under the File > Spreadsheet settings menu item and clicking on the Calculation tab.
If you want to get data from public site(no login) you can use ImportXML. You can google a lot about it, for example
https://answerbun.com/personal-finance-money/get-revenue-details-in-google-sheets-using-google-finance/
If the page you want can only be accessed using login, this becomes a rather complicated task, especially using only apps script libraries (not much scraping lib support here)

Google Apps Script to add xlsx hyperlinked in gmail into Spreadsheet

I have a very specific task and I found many similar questions but they are all slightly different.
The script is triggered every day at 10am based of the top answer of this post: Is it possible to automate Google Spreadsheets Scripts (e.g. without an event to trigger them)?
I receive a report every day with lines that I want to add into the existing spreadsheet, so I get the report around 8am and then the attached data is added to the spreadsheet through the script.
The situation is that the email is an automated report from Amazon Display Advertising Analytics (Amazon DSP) and the xlsx file is hyperlined, not attached.
So the script, ideally gets the email list from my gmail account, searches for a specific email and retrieves a result. Gets the hyperlinked excel file and copies the content, except for row 1 which are the headers. Adds the content to an already existing spreadsheet.
In the end, I had the help of a Fiverr professional who scripted the code, so out of respect for him I won't publish his work, so if you are interested in it or if you need it, write me a private message!
In the end, I had the help of a Fiverr professional who scripted the code, so out of respect for him I won't publish his work, so if you are interested in it or if you need it, write me a private message!

Google Admin Directory SDK Users.list() Returning Old, Not Current, Data

I am working on a project for my company, that well is kind of complicated. I am not sure if I will be able to explain it as well as I need to.
Basically, this is how it works:
A user fills out a Google Form that represents a user in our company, either new or existing
My Google Apps Script gets the last form response, triggered on form submission
That script then relays that last form response data to the custom schema fields I set up on Google Admin
Once the user is updated, I grab ALL the users in the domain and paste them into a google sheet
The spreadsheet represents our company roster. We originally just tried to maintain the data solely in a spreadsheet, but it became a mess.
To solve this, we introduced the google form, which can validate all data. Furthermore, our data is backed up to Google Admin (within custom schema). The spreadsheet is solely for display. It is bulletproof. Upon refresh, it pulls the data, and re-writes the sheet.
However...
I am noticing that after the form is submitted and the user is updated in Google Admin, and then all the users are pulled from Google Admin, the user that was updated isn't showing as updated in the spreadsheet. However, if I refresh the page, then the correct data shows up (I have another script that triggers on spreadsheet open, literally the SAME EXACT code that runs after the form submission). Why does that code return the proper data on refresh, but not when run directly after the form submission and consequent user update in Google Admin?
I really am dumbfounded and having an incredibly hard time explaining this because it does not make any sense. My boss and I both spent the entire day scratching our heads on this yesterday.
Do you guys have ANY ideas?
Is there a cached response, possibly accounting for the non-current data from Google Admin?
When I used the Admin Directory SDK API Explorer, the user modified shows as current. I just don't seem to be getting that same response when my script runs.
I am so lost. I spent 2 months developing this system. It worked in development.
Any and all suggestions are appreciated

Script triggering multiple times after first execution

This scenario is within my company, with google accounts.
I have a google form which of course populates a spreadsheet. My google apps script basically creates a pdf document from the form content and sends it by email to an HR email address. The script also inserts a link to the created pdf in the line on the spreadsheet that has just been populated by the last form submit.
Everything works fine, except the script is triggered automatically a second time after a while creating a second empty pdf, because the form hasn't really been submitted again. It might happen immediately, or after a few minutes, even it once happened one hour after the first execution.
This is owned by a service account. Inside the same account I have another form/spreadsheet/script/trigger which does almost the same and it works just fine, being triggered only once.
The only difference is that the form that works fine, collects the email addresses automatically, so requires a user to login to google.
The faulty one, does not collect the email addresses, it just has the fields "full name" and "username" instead for the person to identify manually.
The executions of both triggers of course, end as "completed".
I been erasing and recreating triggers for two days. Even created the faulty form from scratch, because originally I had duplicated the good one and then modified it accordingly.
You can see in the image, the execution at 6:04:49 is a "ghost" of the one one second before. (of course I cannot do all the form filling process in just 1 second)
Then another real execution at 5:33:42 and its ghost 4 seconds after that.
Then the 3 executions at 5:39:07 seem to be ghots of previous ones done at different times.
Any clues?? Thanks a lot!

Auto populating Google Calendar based on Google Sheets document

I've read a lot of posts related to my problem... The problem is I'm not a computer programmer and it's like reading a foreign language to me. I've tried to muddle my way through it but to no avail. I've mainly been working from this post and the links from that page.
I have a Google Sheets document with a list of id numbers and a start date and end date for treatments. I'd like to be able to run a script that will auto populate a Google Calendar with the id numbers as the event title and the treatment time frame. I don't need a start and end time, I'm only looking for dates.
I would also like to create another Google Calendar from the same spreadsheet. I have 6 columns associated with each id number - a projected date and an actual date for 3 different types of testing. I would like to be able to run another script that populates a Google Calendar with the type of testing as the event title. Again, not concerned with times at all, just the dates.
I'm using this to track an experiment I'm running and it's just a lot of information to see on a spreadsheet. It would be nice easier to see all the testing I need to do in a calendar format so I don't make any more mistakes in missing testing days or when to stop treatments.
I've been trying for 3 weeks to figure this out on my own. Let's just say, I know nothing about coding...
You should try writing a function in Google Apps script.
Get the active sheet, get range and retreive the id numbers and a start date and end date.
Then create a calender event by referring to this link.
Hope that helps!