Google Spreadsheet row update - google-sheets

I need update a row with function =importxml() every 3 minutes to refresh MAP gadget.
I setup function redROWs trigger to every 3 minutes but it doesn't work.
Any idea?

The importXML() is updating every 2 hours by it self and you can't trigger it from a script. Then you have to write the function into your script..
The best solution I found is to add the GoogleClock() to the URL. It makes the ImportXML update every minute automatically. Also when the spreadsheet is not open.
Like this:
ImportXML("URL"&GoogleClock(),"div...")

getActiveSheet() only works when you have the spreadsheet open - use openById
https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app#openById(String)
to trigger =importxml , write something to the sheet.

Related

Google Sheets - Autoreplace a value when a new row is created

I use Zapier to create a new row in a Google Sheet doc for each new registration on our website. However, I want to autoreplace a value of a cell when the row is created or, if it's not possible, using a script with onOpen, or any time-based trigger.
Here is an example of the data that needs to be changed in two specific columns (say, A and C)...
/*Job - Column A - English to French*/
'Management':'Gestion',
'Social work':'Travail social',
'Reception':'Accueil',
'Art Therapy':'Art-thérapie',
'Volunteer work':'Bénévole',
/*Workplace - Column C - English to French*/
'Starting Community':'Communauté en démarrage',
'CLAN Program' : 'Programme FER',
'Other (specify)' : 'Autre affiliation',
'University (specify)' : 'Université',
How can I do that? I managed to use an onEdit trigger, but since it can't be activated by Zapier, it's useless.
Thanks!
You cannot achieve this behavior with an Edit trigger in Apps Script.
Zapier will edit the Spreadsheet via API call and this is actually one of the trigger limitations:
Script executions and API requests do not cause triggers to run. For example, calling Range.setValue() to edit a cell does not cause the spreadsheet's onEdit trigger to run.
You should probably craft this auto-replace feature in the Zapier environment directly.
Refer to this documentation for additional Apps Script triggers limitations.
The workaround I use for having automatic functions applied on the row created in a Google Sheet by Zapier is by doing the automation with Google Sheet functions. Your document should have 3 tabs:
Where Zapier will create new rows
On this tab, you will use the IMPORTRANGE function (to import all the data from the tab1).
Where you can do your magic (functions doing exactly what you want, using reference to the cells of the tab2).
Optionally, you can then hide the first 2 tabs, once your setup is complete on the tab3.

Triggering a script on a google sheet after editing a separate sheet

Hello, I am making an initiative table for D&D using google sheets.
At the moment I have a Mainsheet in which myself (the DM) can edit and change, and Playersheet that has the data the players need using IMPORTRANGE.
I am attempting to write a script that will automatically hide all empty "initiative" cells in PlayerSheet .
I have successfully coded this script, however I would like it to trigger any time I edit the MainSheet.
Because all the date in the sheet comes from using IMPORTRANGE I am not able to use the on edit trigger, as the PlayerSheet is never edited.
Is it possible to have the script located in PlayerSheet run whenever I edit MainSheet?
On top of that would it be possible to have the script only run when I edit data in the F column?
To run the script whenever you edit your spreadsheet, you can create a fonction on edit.
function onEdit(e){
var range = e.range;
//here you can check if the column if F or not and run your code.
}
Tu change the values of another spreadsheet, when selecting the spreadsheet you want to do the actions on, instead of selecting the active one, you can edit one with the url. Something like :
var doc = SpreadsheetApp.openByUrl("paste the url here");
var sheet = doc.getSheetByName("Name of the sheet");
etc...
And then do the modifications you need to do on the players spreadsheet.

Bringing in a google form response to a sheet

Here is a copy of the sheets and form (form > go to live)
https://docs.google.com/a/ncsu.edu/spreadsheets/d/1mEz9mLEgP4Cfts2ZU6NwhNiL6xjWdFbt42RUj-RYbZw/edit?usp=sharing
So currently, I get responses in a different sheet. Ideally, I would get the response on the tracking sheet with the appropriate format for the dates. Additionally, I would like to keep the functionality of the tracking sheet which is to be able add in items by hand and not through the form. I currently have a script in place which auto-inputs the current date as the two separate formats.
So I'm looking for a solution which either takes in form response to the sheet and appropriate cells (the first empty cell). Or I'm looking to create a script which onEdit which when the form sheet is edited, will fetch the new response and copy it over appropriately onto the tacking sheet.
I have tried googling answers.. But I think I may be a failure at it since I wasn't able to really find a solution for this particular problem. Thank you in advance for the help!
form:
https://docs.google.com/forms/d/1AHSQrLkq3U7NJMvgWoH3lAygova7Mi4BaXHdROaaS2g/edit?usp=sharing
The script associated to this form should do the trick.
All the explanations on how to use it are in the response sheet

Refresh ImportHTML

I have a sheet that is importing data using ImportHTML. The data changes quite frequently, is there any way to have Google Sheets automatically refresh the data?
I tried adding & year(now()) & month(now()) & day(now()) & hour(now()) & minute(now()), to the formula but I get the following error:
This function is not allowed to reference a cell with NOW(), RAND(), or RANDBETWEEN()
"Any way"? Yes, but as Mogsdad has mentioned 'round these parts before, "Since the retirement of the GOOGLECLOCK function, there is no formula that will trigger automatic recalculation."
Using Google Apps Script and something like...
function getData() {
var queryString = Utilities.formatDate(new Date(), "GMT", "yyyyMMddHHmmss");
var cellFunction = '=IMPORTHTML("<your-url>?' + queryString + '","<your-query>",<your-index>)';
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("<your-sheet>").getRange('<your-cell>').setValue(cellFunction);
}
...should get you there. After saving, naming, and authorizing the script, set up a trigger so it runs/refreshes the data as frequently as you'd like.
Very late to the question. I recently had to do a similar thing. I thought I'd write something up here for others to find useful..hopefully.
My Use Case:
I wanted my google sheet to call IMPORTDATA on a specific url every few minutes because the data stored against that url was being changed by a Timer Trigger and an Http Trigger Azure Function.
Basically, I wanted my google sheet to get refreshed every 5 minutes because I knew the data against the url keeps changing.
What I Tried:
I started out with a similar script to what #greg alluded. (Cheers for that.)
I setup a timer trigger for that script to be 5 minutes. All looked hunky-dory.
Issues:
I realised that setting the function as a value on the cell caused the function to run only at the start when the sheet was empty. The second time the trigger hit, the sheet did not get refreshed.
So I tried
cell.setValue("");
cell.setValue('=IMPORTDATA("my-url")');
No Luck.
The sheet did not get refreshed with the new data. It seemed as if the sheet saw that the value-to-set in the cell is the same as the existing value, so it did not bother re-running the function.
To confirm my hypothesis,
I manually tried:
Cut the IMPORTDATA function from the google sheet cell.
Paste the value back into the cell.
The sheet did not get refreshed.
But when I manually tried:
Remove/Change the url from/in the cell. Hit Enter.
Paste the formula again in the cell. Hit Enter.
This worked. So, it seems that cell.SetValue() or even cell.setFormula() just doesn't re-run the function I was setting because the same function existed in the cell to start with.
My Solution best suited to my use-case:
Since the data against the url, I was pointing to, was already in CSV format,
I did something like this:
var firstSheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
var text = UrlFetchApp.fetch(url).getContentText(); //gets the data.
var csv = Utilities.parseCsv(text); //parses the data.
var range = firstSheet.getRange(1, 1, csv.length, 17) //getting the range.
range.setValues(csv); //setting the data.
I'm basically grabbing the data from the url and putting it into the sheet on timer instead of calling the IMPORTDATA function since that approach didn't quite work out for me.
You could do a similar thing, assuming you want to get some sort of table or chart content and save the values to your sheet.

how to refresh google spreadsheet (and specifically the now() function) every x seconds?

I would like google spreadsheet to automatically refreshes calculation. I have made simple timers with NOW() and I would like to see the timer going down
So far, I have tried the googleclock() function and is only updated every minute, which is not
enough.
Thank you
Write script and try Class ClockTriggerBuilder : https://developers.google.com/apps-script/reference/script/clock-trigger-builder?hl=en
and use this method for periodically creating trigger: https://developers.google.com/apps-script/reference/script/clock-trigger-builder?hl=en#after(Integer)

Resources