Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Import JSON refresh with Sheet Trigger #49

Open
RonKon opened this issue Oct 31, 2017 · 8 comments
Open

Import JSON refresh with Sheet Trigger #49

RonKon opened this issue Oct 31, 2017 · 8 comments

Comments

@RonKon
Copy link

RonKon commented Oct 31, 2017

Hi,
the script works perfectly and is really helpfull for me.
It is possibile you implement the function sheet trigger to create a automatic refresh.
I have tested so many variants of refresh but all not working with your script.
Thank`s in Advance for help

@RonKon
Copy link
Author

RonKon commented Nov 3, 2017

it`s done

@xyzzy529
Copy link

xyzzy529 commented Nov 16, 2017

How did you do it @RonKon? How is this used? Is there an example?

I just put a PR #51 in to make a "recalc" parameter. Which when the referenced cell is changed (manually for my purposes) then the ImportJSON() is re-loaded and the sheet recalcs.

example:
=ImportJSON("https://api.fixer.io/latest?base=INR&symbols=USD","","rawHeaders",B1)

Changed:
function ImportJSON(url, query, parseOptions, recalc) {

@xyzzy529 xyzzy529 mentioned this issue Nov 16, 2017
@Vadorequest
Copy link

See #59 (comment)

I guess we can close this and only use one issue, seems to be a duplicate.

@akonyar
Copy link

akonyar commented Apr 11, 2020

I've had same problem, first I tried to clear the cell that contains formula then set the formula again, but it doesn't work. When I add SpreadsheetApp.flush() between these steps, it worked perfectly.

function reCalculate() {
//reCalculate Data Import sheet by empty cell that includes ImportJSON function (B8), flush then set code again.
var ss = SpreadsheetApp.getActiveSpreadsheet ();
var sheet = ss.getSheetByName("DATA IMPORT");
var cell = sheet.getRange('B8')
cell.setValue('')
SpreadsheetApp.flush()
cell.setValue('=ImportJSON("YOUR-JSON-LINK","","noHeaders,noTruncate")')
}

@0xRampey
Copy link

0xRampey commented Mar 9, 2021

@xyzzy529 If the referenced cell is set to an auto updating value like =GOOGLEFINANCE("Currency:USDINR"), all the ImportJSON() reload and the sheet recalcs every few minutes too!
Thanks for the hack

@eemreyesil
Copy link

I've had same problem, first I tried to clear the cell that contains formula then set the formula again, but it doesn't work. When I add SpreadsheetApp.flush() between these steps, it worked perfectly.

function reCalculate() {
//reCalculate Data Import sheet by empty cell that includes ImportJSON function (B8), flush then set code again.
var ss = SpreadsheetApp.getActiveSpreadsheet ();
var sheet = ss.getSheetByName("DATA IMPORT");
var cell = sheet.getRange('B8')
cell.setValue('')
SpreadsheetApp.flush()
cell.setValue('=ImportJSON("YOUR-JSON-LINK","","noHeaders,noTruncate")')
}

@akonyar Thank you so much for this hint. Indeed it works. thanks again

@zenminimalist
Copy link

@akonyar @eemreyesil Is there a way I can change this code to get a sheet to only refresh/update when say cell A1 is TRUE (e.g. checkbox is ticked), so I can prevent API calls via importJSON from being made in that sheet? Similar to a "kill switch". It only updates when the check mark is FALSE
If so, how would the code have to look like?

@eemreyesil
Copy link

Somewhere in the spreadsheet write True and in the below cell, False. Then select A1. Under Data tab, click data validations, for select from range box, select the cells you wrote down True and False. In the code, define a variable for A1 cell. Put a condition such as if this variable is True {...} else {}. If you want auto refresh (in case it is True), you may use recursive functions. You can call the same function under the first if statement(if True{return reCalculate()}) and under the else statement, you can type return something else.

I hope I may help you.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants
@xyzzy529 @0xRampey @Vadorequest @zenminimalist @akonyar @RonKon @eemreyesil and others