简体   繁体   中英

Custom Google Sheet Function Updating Without Any Cause

I'm using a custom function to pull price data for EVE Online and I would only like the function to update upon a specific cell change. Instead it's updating every ~10-20 minutes which is using up a ton of my daily quota for URL Fetches.

Looking below you can see the main function is in a page labeled "Warehouse Stock". It pulls all price data for items in the "Item" column. The cell refreshes with a custom function that changes cell B4 in the utility sheet. When that cell changes it updates the values in the custom function because of the IF/THEN statement. Lastly the prices are loaded into the main sheet and sorted by the "product" column.

Also I have recalculation "On Change" and Iterative Calculation turned off.

Thank you for reading and any help you can provide.

The custom function is:

    /**
* Query's Fuzz market API for the given types
* @param {range} A vertical range of type_ids.
* @return maxBuy and minSell for each type_id
* @customfunction
*/
function fuzzApiPriceData(type_ids) {
  if (!type_ids) throw 'type_ids is required';
  const ids = Array.isArray(type_ids) ? type_ids.map(id => id[0]) : [type_ids];
  const fuzz_price_data = JSON.parse(UrlFetchApp.fetch(`https://market.fuzzwork.co.uk/aggregates/?station=60008494&types=${ids.join(',')}`));
  return [['minSell', 'maxBuy']].concat(type_ids.map(type_id => [parseFloat(fuzz_price_data[type_id]['sell']['min']), parseFloat(fuzz_price_data[type_id]['buy']['max'])]));
}

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

What I usually do for that is: put a checkbox in a cell. Then, when calling your custom function, add an extra reference to that cell, even if the parameter is not included in your custom function. Each time you will switch true/false, your custom function will be reactivated. Then you can also define another function with a trigger that just change the value of true/false. Here is an example in sheet 'Data' cell A3: the function is getDataJSON(C1,A2:U2,A1) with A1 even if the custom function take into account only the first and second parameter. https://docs.google.com/spreadsheets/d/1DN0Gfim0LC098zVgrUpt2crPWUn4pWfZnCpuuL1ZiMs/edit?usp=sharing

i think there's a fairly basic misunderstanding here.

"Custom functions" are designed to be written in cells on a sheet. they are by there nature designed to run ALL the time, constantly updating.

If you are attempting to run a custom script , you do that from the script editor itself, you don't even write the function in a cell at ALL .

I'm assuming you didn't write the "custom function" you're using(?) So it will be a bit difficult (but not impossible.) to convert it to a script that writes to a certain place on the sheet at a certain time, But you might research a bit more about the difference between custom functions designed to be executed in cells. and scripts designed to be run on a time trigger.

Regarding you answer:

I would like the function to refresh everyday, aswell as having the option to manually refresh the function by the contents of the cell Utility!B4

I propose you to use Installable Triggers :

  1. Time-driven trigger : It can execute a function each day at specific time.
  2. Installable edit trigger : It can execute a function when a certain value in a specific cell changes.

However, if you want to execute a function manually, I recommend you to insert a drawing and assign a function to it.

Reference

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