0
votes

I have an API function to extract data from Amazon, I need to have 'fetch' & 'get' report function separately to achieve action for

  1. request fetching report from Amazon, and
  2. get report from Amazon, and the request action take about 2 mins for Amazon to finish the fetching request and allow for getting the report, so in the script I have set script.newtrigger after 2 minutes.
function fetchReportMarketListTrig() {
  fetchReportMarketList(true);
  ScriptApp.newTrigger("getReportsForAccountMarketListTrig")
  .timeBased()
  .after(2* 60 * 1000)
  .create();
  Logger.log("Report Request Created");
}

The function worked perfectly when I manual trigger it from menuitems, getReportsForAccountMarketListTrig will be called after 2 minutes. However, if I set auto trigger, fetchReportMarketListTrig cannot call getReportsForAccountMarketListTrig. we need to seek the answer of why the sheet is acting different from manual trigger and auto trigger. Thanks a lot!

Manual trigger from menuitems

Auto trigger set in google sheet time-driven trigger

Auto Trigger and Manual trigger execution result

1
How are you triggering fetchReportMarketListTrig?Rafa Guillermo
Hi @RafaGuillermo, Thank you so much for the response, I just added the screencap for how I manual trigger and auto trigger fetchReportMarketListTrig in the flag.Jim pang

1 Answers

0
votes

Answer:

You have two functions with the same name! This produced undefined behaviour when you create a trigger for this function.

More Information:

In the screenshot you provided for your trigger, you are displayed the following warning:

enter image description here

Functions within the same project must always have a unique name!

Imagine the following code:

function doSomeMath() {
  var x = 1 + 2;
  console.log(x);
}

function doSomeMath() {
  var x = 100 + 200;
  console.log(x);
}

And then you ask your trigger to run function doSomeMath() - how does it know which one you mean?

Fix:

The likelyhood here is that the other function in your code canned fetchReportMarketListTrig is what is running on the time-based trigger, and not the one you intend to have run.

To fix this, search your script file for the functions named fetchReportMarketListTrig, and rename them so that they are unique. You can then set up your trigger on the function you wish as normal.

I hope this is helpful to you!