Initialize a DocType

Hey there…

I want to create doctype B from joining doctype A ( means doctype B knows doctype A )

so for exampe, user is on doctype A… fills out all fields and save doctype A… now he must klick a button or something to create doctype B. After clicking the button doctype B shows up and be inizialized with values from doctype A and linked values ( as example think about doctype A has a customer as link field and on doctype B usses address from this customer to show up )

I dont know what i searching for to get right advice …

If I understood you correctly, you are asking to create a new document (in Doctype B) everytime a document (in Doctype A) is submitted.
If you are asking how to automate this, use server scripts.
If you are asking how to get values from another doctype, in Doctype B create a link field that links to Doctype A. Then create your required fields in Doctype B and in the field properties of every field, set it to fetch from the link field you created initially. The fetch value depends on the field you would like to get.

If you are asking for a way to achieve both options, use a server script that triggers on submit. Provide more details if you need help in this, or search the forum there are a lot of similar questions.

i probably made a mess with my question…

i try to explain it with steps because of my english knowledge…

  1. user creats a new DoctypeA and fill its fields (one of the field is a link field to customer )
  2. user saves DoctypeA
  3. on top of DoctypeA a Button appear (Label of the button: “Create new DoctypeB”)
  4. user klicks on the button
  5. Desk changes to a new DocTypeB and link this new DoctypeB with the DoctypeA he was created from
  6. user see a new DoctypeB with preinizialised fields ( Street from Customer as example and the customer from DoctypeA itselfs)

i know that i need server script because of the prefetches where is to do… because of my requirement i need some informations or links where i can use to research…
How change desk to new doctype and link this to the source doctype… is maybe the main question at his point to going on

Search for frappe.model.sync in erpnext source code, you will find plenty of examples where it is used to sync the new doc created by server.

Afterwards, frappe.set_route is called to redirect to the new doc page.

Another technique I like to use is to create new doc client side, and then call an init_new method on it.

This is the client side code in your DocA’s button “Create new DoctypeB”

frappe.model.with_doctype("DoctypeB", function() {
	let new_doc = frappe.model.get_new_doc("DoctypeB");{
		doc: new_doc,
		method: "init_new",
		args: {
			docA: docA
		freeze: true,
		callback: function(r) {

And this is the server code in DoctypeB

def init_new(self, docA):
	self.customer = frappe.get_value("DoctypeA", docA, "customer")

You could even ditch the whole call to server if everything is available client side

frappe.model.with_doctype("DoctypeB", function() {
	let new_doc = frappe.model.get_new_doc("DoctypeB");
	new_doc.customer = frm.doc.customer;