0

I just want to add simple spin counter button like the html one in google sheets app script cell and get the value by increasing or decreasing.

<input type="number">

This's the function to import data and return ImportJson() but it doesn't update at all when it returns something it's fixed.

So the condition is get the value of `A2' then make some API calls then the final API call. but even when I write values in A2 cell it doesn't update the function return.

function ImportData1() {


  var Final_result = [];
  var VenueId_results = [];

  var PageNumber_index = 0;
  var Page_number = [0, 1, 2, 3, 4];
  var New_URL = "";

  var url = "https://app.ticketmaster.com/discovery/v2/events?sort=venueName,asc&locale=*&size=199&" + "page=" + Page_number[PageNumber_index] + "&apikey=" + API_key + "&venueId=" + venueIds;
  // ImportJSON(url, "/","noInherit,noTruncate,rawHeaders");
  // console.log(ImportJSON(url, "/", "noInherit,noTruncate,rawHeaders"));

  //  console.log("Veuneid" + Veunue_id + Venue_Id_List.length);
  console.log("ImportData1();" + Venue_Id_List.length);

  var New_Venue = SpreadsheetApp.getActiveSheet().getRange('A2').getValue();

  if (typeof New_Venue != "undefined" && New_Venue != null && !New_Venue == "") {



    var Venue_arr = New_Venue.split(",");


    VenueId_results = Add_new_VeunueId(Venue_arr);

    var Last_New_Id_Venue = "";

    for (var Index_venune = 2; Index_venune < (VenueId_results.length) - 2; Index_venune++) {

      console.log("Venuesid " + VenueId_results[Index_venune]);
      var New_Id_Venue = VenueId_results[Index_venune].toString() + ",";

      Last_New_Id_Venue += New_Id_Venue;
      console.log("New_Id_Venue " + New_Id_Venue);

    }
    console.log("Last_New_Id_Venue " + Last_New_Id_Venue);

    New_URL = url + Last_New_Id_Venue;

    New_Venue = "";
    VenueId_results = [];

    return ImportJSON(New_URL, "/", "noInherit,noTruncate,rawHeaders")
    for (; PageNumber_index < Page_number.length; PageNumber_index++) {

      console.log("looopsyes");

      Final_result = Final_result.concat(ImportJSON(New_URL, "/", "noInherit,noTruncate,rawHeaders"));
      console.log("New_URL " + PageNumber_index + Page_number[PageNumber_index] + Final_result);

      Utilities.sleep(1000);
    }
    console.log("New_URL " + New_URL);

    return Final_result;
    console.log("New_URL " + Page_number);




    return Final_result;
    //  url += New_Venue;

    var New_URL = url + New_Venue;
    console.log("hello" + New_URL);


  } else {
    console.log("hellono");
     New_Venue = "";
  VenueId_results = [];
      return ImportJSON(url, "/", "noInherit,noTruncate,rawHeaders");

  }

}
Mark
  • 3
  • 3
  • ok, now i understand that your spinbutton will increase or decrease the value of A2. So my proposal works and you will need to add a call to your function. However, as you say "but even when I write values ​​in cell A2, it doesn't update the return of the function", so the main problem is your function, not the spin button! – Mike Steelson May 28 '22 at 15:24

1 Answers1

0

Try

const rng = SpreadsheetApp.getActiveSheet().getRange('A2')
function increment() {
  rng.setValue(rng.getValue() + 1);
  SpreadsheetApp.flush();
  ImportData1();
}
function decrement() {
  rng.setValue(rng.getValue() - 1);
  SpreadsheetApp.flush();
  ImportData1();
}

and assign each script to a drawing as you wish, for instance

enter image description here

Mike Steelson
  • 14,650
  • 2
  • 5
  • 20
  • It's good but everytime I click the button it prints a notify running script. but how can I trigger another function in `'A4'` for example by clicking the image. – Mark May 28 '22 at 14:08
  • I have `ImportJson()` function that doesn't update its value unless I make changes to Appscript then reload the sheet again, I think it was running but suddenly stopped. – Mark May 28 '22 at 14:09
  • why are you using importjson? can you share a minimal reproducible example? and explain what the importjson function does in your project and why you need the spin button accordingly. – Mike Steelson May 28 '22 at 14:20
  • Thanks I updated and added the function that I want to trigger. – Mark May 28 '22 at 15:15
  • I updated my answer...however, you need to be sure that your own `ImportData1()` function works as expected. If you need help specifically with this feature, please open a new topic. – Mike Steelson May 28 '22 at 15:27
  • I made a new topic I just hope I get a help it was strange because it was working this's the link : https://stackoverflow.com/questions/72418370/google-sheets-and-appscritpt-doesnt-update-the-function-properly – Mark May 28 '22 at 18:43
  • for this one, can you validate so that others can benefit to the solution? thx – Mike Steelson May 28 '22 at 19:29