0

I have been struggling this for a while. I am creating an item with a form. After the item is created, I want to redirect the user to a page, where the datsource's current item is set to this new one. How would this be possible? I tried

  var keyofCustomer = record._key;
  google.script.run.getCustomer(keyofCustomer);
  app.datasources.Customers.item=currentCustomer;
  app.showPage(app.pages.CustomerDetails); 

the getCustomer server script:

    function getCustomer(customerID)
   {
    var customer = app.models.Customers.getRecord(customerID);
    return customer;
   }

Any kind of help would be much appreciated.

Koczka Bence
  • 85
  • 2
  • 12
  • 1
    Typically if the datasource for the create form is the same as your view/edit page datasource then the last created item is automatically the selected item in this datasource. I would recommend just implementing the switch to page in your create form within the success function of createItem(). The way you have it set up right now could be considered as inefficient, and there are some missing items such as what is ‘currentCustomer’ don’t see it declared as a variable or anything. – Markus Malessa Nov 24 '19 at 15:29
  • Thank you for your answer. When I switch to the details page in the success function of createItem(), the current item is the not the newly created one, but the first one of the query which is made on the datasource. I am not sure if I am phrasing it right, but the current item is the one which is on the top of the list, If I visualize the items asa list of the datasource in a table. – Koczka Bence Nov 24 '19 at 16:18
  • Are the details page and create form the same base datasource, as in ‘Customers’? – Markus Malessa Nov 24 '19 at 16:22
  • the details page uses the "Customers" datasource, and the button on the create page wich fires the save (widget.datasource.saveChanges) is set to "Inherited: Customers(create)". – Koczka Bence Nov 24 '19 at 16:30
  • Would you mind sharing the full code for the create item button? – Markus Malessa Nov 24 '19 at 16:38
  • of course, here it is: https://pastebin.com/A4rE2jjs – Koczka Bence Nov 24 '19 at 16:46
  • I agree with @MarkusMalessa. Just make sure the page where the user is being redirected has the datasource set to `Customers`. – Morfinismo Nov 26 '19 at 00:20
  • It is still hard to tell what exactly is happening. Unless you reload your datasource somewhere in the process of creating an item then my initial comment stands. As long as datasource for create form and datasource for detail page are the same then the last created item is always the currently selected item. I have this exact type of setup over a dozen times in my own app and it works flawlessly. – Markus Malessa Nov 26 '19 at 14:40
  • thanks for the help, I will figure it out! – Koczka Bence Nov 27 '19 at 18:05

0 Answers0