[Custom Scripts] Creating Doc from Button Click Event => Glitch in Passing Parameters

Hi all, I’m having issues with a custom button. Here is the basic thing I need to happen;
I have one form (where the button is). This form is used to fill out information and then the user clicks a button and the code is supposed to take certain values from the actual page and pre-fill a samples form with that information.

Here is my code:

var Sample = frappe.model.get_new_doc("Sample");
frappe.route_options = {
frappe.set_route('Form', 'Sample', Sample.name);

This is what’s happening:

  1. User fills out form. Clicks button. [Correct!]
  2. User is then navigated to Sample Form. [Correct!]
  3. Data is not preloaded. [Not Correct]

But, if the user navigates back (with the browser) and clicks on button again, the following happens:

  1. User is navigated to Sample Form [Correct!]
  2. Data IS PREloaded [Correct!]

So basically this code should be correct, but I am not able to load the data for the new document on a first attempt. Is this a glitch, or am I missing something?

try this in the last line :
frappe.set_route(“list”, “/new ”);

Hi @ablishek,

Here check its syntax.

frappe.ui.form.on('Your DocType', {
	refresh(frm) {
		frm.add_custom_button(__("Button Name"), function() {
				frappe.route_options = {
					"model": frm.doc.model_name,
                    "season": frm.doc.season
				frappe.set_route("your-doctype", "new-your-doctype");
         // eg. frappe.set_route("sales-invoice", "new-sales-invoice");
			}, __("Create"));

Please set your according field and doctype.
Then reload and check it.

Thank You!


Thank you for your help its working very good.
please how to fetch customer name to new doc?
thanks in advanced
thank I find the solution in
Frappe UI Dialog