简体   繁体   中英

Custom function getting data from API not updating

I have a custom function that get data from an API and it works. The problem is that the data it gets changes within minutes, but the cell where I call the formula doesn't update. If I recalculate it (pressing enter) it doesn't update either. I have to delete the formula from the cell and re-enter it to get the data updated. I guess the code isn't running again as the google sheet sees that nothing in the workbook has changed.

How can I make it to update each 5 minutes for example?

So let us assume that you have a function named getData() that returns the data.

Instead of returning the data, you could make the function insert the data to a specific cell calling

SpreadsheetApp.GetActiveSpreadsheet.GetActiveSheet().GetRange(row, col).setValue(data);

Now you could create a trigger that calls the function every five minutes. One example is doing it programmatically like so:

function createTimeDrivenTriggers() {
 // Trigger every 5 minutes.
ScriptApp.newTrigger('getData')
 .timeBased()
 .everyMinutes(5)
 .create();

Remember to execute the triggerbuilder from the code editor.

Hope this was clear enough and helped at all. I'll proofread and test the exact formatting once I get to a computer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM