Route Options Disappear


I’m creating a custom script that:

  1. Creates a button at the top of my page → works
  2. Links this button to a Sales Invoice → works
  3. Updates my current form status to “Closed” when I create an Invoice from it → partially works
  4. Fills in certain parts of my invoice automatically → partially works

For the status update, I am able to update the status on the form, but I still need to save the form manually for it to be updated in the system. I tried using, but that just makes my whole script not work any more (no error shows up). Any idea on how I can do this?

To fill in the fields of my invoice, I am facing a challenge. I am able to fill in the customer field without any problem. When I try filling in the project field, I see “Test” brielfy appear in the new form, but then it disappears. Is there a way of putting a timeout in route_options ?
I also want to automatically will in a checkbox and child table (i.e. with items), but they don’t work either. Hard to say if it can also be solved using a timeout or not, but I don’t see them briefly appear.

Here is my code:

frappe.ui.form.on('Issue', {
    refresh: function(frm) {
      frm.add_custom_button(__('Repair Invoice'), function(){
	frm.doc.status = "Closed";
	frappe.route_options = {
		'customer': frm.doc.customer,
		'project': "Test"
	frappe.set_route('Form','Sales Invoice','New Sales Invoice 1');
    }, __("Make"));

Thanks for your help!