2

After I call app.saveRecords() in server script I have to hit refresh (in Chrome) on any client pages to reload the datasource. Is there something I can call after saveRecords() on the server to force the clients to refresh?

Jim
  • 33
  • 4
  • 2
    If you are referring to the model onBeforeSave or onAfterSave events, then you should implement a manual save datasource instead of an autosave one and call the client side datasource.saveChanges() with a call back function to initiate your client datasource reload. If you are running a server function that gets initiated from the client via google.script.run then you can implement .withSuccessHandler() and .withFailureHandler() functions on the client to provide a call back. You should provide more detail relating to your circumstances in order to provide a relevant answer. – Markus Malessa Apr 25 '19 at 17:33
  • I have an "add record" page and a different "list records" page. The add record page creates an object and calls some server script that adds the record. The add record page is not data bound because I needed to scan a barcode into a relation field (can't do with dropdowns that appmaker generates). The "list records" page is data bound, but will not update unless I refresh in Chrome. The server callback would go to the "add" page, but that doesn't help to update the "list records" page. I'm looking for something like "app.pages.listpage.datasource.refresh" from server script. – Jim Apr 25 '19 at 18:02
  • Ok, so how are you calling the server script on the 'add record' page? Is it with google.script.run? If it is a stand alone server script that does not get called from the client, then there is no way to initiate a datasource reload on the client. It would help if you included relevant code (client/server) in your question. – Markus Malessa Apr 25 '19 at 18:53
  • Adding widget.root.datasource.load() in the withSuccessHandler made it work. That made the other pages that use that datasource refresh. – Jim Apr 25 '19 at 18:56
  • I had same problem when I build a todo list, when I modify each item in the list, that may lead to change of the status of whole list, to have that itemChange and listStatus linked, I used server script implemented in onAfterSave() of list Item model, using server script instead of client script help avoid all UI interaction complexity, but problem is I cannot find a call mentioned by Jim at 18:02 to have the server change on todo list status updated on UI. yes, google.script.run can be used as workaround, but that will break the simple solution. A client side record listener is needed. – Albert May 01 '19 at 21:35

1 Answers1

1

This client script code worked:

function addCont(widget) {

  var holder = widget.root.descendants;

  var con = {
    barcode: holder.Barcode.value,
    part: holder.Part.value,
    location: holder.Location.value
  };

  google.script.run.withSuccessHandler(function(result) {
    console.log("Container Added");

    // This forces the other pages to reload after the server adds the record
    widget.root.datasource.load();

    clearAddCont(widget);
  }).addContainer(con);
}
Jim
  • 33
  • 4