Search code examples
inserteditgoogle-app-maker

How to open a page to a new record (insert) vs existing (edit) using the same edit page


In G App Maker, I display a list of records and a + to add records. If I click on a row, I go to the edit page and its all works. I can edit/delete that record and return back to the list. Now on the (+) I want to go to that same page but this time to a new record. I can't find via code how to insert a new record then open my edit page?

Today I have created two pages one as an INSERT ONLY page and one as an EDIT page. They have cascading pulldown lists. For maintainability, I would like to use just the one EDIT Page, so I don't have to maintain code for both.

How do I insert a record and open the edit page to that record using a button?

I have tried to create a new record, but it just creates a new record in my list and I don't know how to switch/open the edit page on that newly created record. My List page is not editable.

OnClick:

widget.datasource.createItem(function() {
    editReceivingLog(widget.item._key , app.pages.EditReceiving );
});


function editReceivingLog( _key, _page) {
  var params = {
    openKey: _key
  };

  app.showPage(_page);
  google.script.history.replace(null, params || {}, _page.name);
}

It looks like it creates a record but does not open the EditReceiving page


Solution

  • In the (+) button make sure that the datasource is the same as the edit page. Then simply do...

    widget.datasource.createItem(function(){
        app.showPage(app.pages.yourEditPage);
    });