Linking a document B to the document A from which it was created

Hi All,

I have a button on a form for doctype A. When I click it, frappe.set_route is called in A.js which takes us to the form for doctype B.
Doctype A contains doctype B as a link field.
How can I link the document created for B to the parent document of A?
Maybe by passing a parameter from A to B when I call frappe.set_route?

Regards,

I think if someone could show me how to retrieve route_options when redirected by set_route then I’ll be fine.

Regards,

Hi @Chude_Osiegbu,

You can use the frappe.model.open_mapped_doc from document A. It will redirect you to document B and you will be able to access the document A’s fields.

Please check the lead.js and lead.py.

Thanks,
Makarand Bauskar

Many thanks @makarand_b

Is there somewhere that descriptions of all these api’s like frappe.model.open_mapped_doc can be found?

Regards,

Hi @Chude_Osiegbu,

Please check http://frappe.github.io/frappe/user/tutorial/

Thanks,
Makarand Bauskar

Thanks. I’ve gone through there but there isn’t a list of api’s described there.

Regards,

@Chude_Osiegbu unfortunately its not documented. Client side documention is WIP

Thanks @rmehta

I would still like to know how, from a Controller (e.g. Address.py), I can retrieve the values that are specified in route_options.

I have the following lines in my code but it’s not clear to me how to get access to the source_doctype and source_docname in the Address.py file:

var new_address = frappe.model.make_new_doc_and_get_name(“Address”);
frappe.route_options = {“source_doctype”: cdn.doctype, “source_docname”: cdn.name}
frappe.set_route(“Form”, “Address”, new_address);

Regards,

You can’t push values to route_options from server-side.

Ok, Apologies if my question isn’t clear. From your statement, I assume that route_options can only be pushed and retrieved on the client-side java-script. Can you confirm that?
Also, an example of how the parameters passed in the route_options can be retrieved at the receiving end would be great. Many thanks for your support.

Regards,

We found unexpected behavior if use frappe.model.open_mapped_doc.

Problem is with name_series.

Document A (has name_series: AAAA)
Document B (has name_series: BBBB)

Maping code:

def make_B_from_A(source_name, target_doc=None):
   doclist = get_mapped_doc("Document A", source_name, {
      "Document A": {
         "doctype": "Document B",
         "field_map": {
            "name": "link_to_A_Document"
         }
      }
   }, target_doc)

   return doclist

We expected to see READ-ONLY link in Document B to parent Document A.

function create_B_document() {

frappe.model.open_mapped_doc({
method: “app.make_B_from_A”,
frm: cur_frm
})
}

But after mapping we see that B Document has name_series: AAAA

Document B naming after mapping:
AAAA-00005
AAAA-00006
AAAA-00007

It looks like a bug or not?

1 Like

Add link - [Name_series] - Unexpected behavior if use frappe.model.open_mapped_doc · Issue #2330 · frappe/frappe · GitHub

Hi, as I understood correct your Document B should have BBBB name_series, right?
If yes… try this way