I have created a custom doctype - product and it has a field -product and naming series as PRO.#####. I have given it as a link field to another doctype. When i select product it is showing the series first as below,
After selecting the option it is showing only the series, i need the product field to be shown,
at the time, you have in your custom doctype a link field called product which links to “your_product_doctype”.
Now you need a second field (type “Data”) in your custom doctype wich fetch the “Product Name” from “your_product_doctype”. There for you have to add a new field something like that:
// return placeholder text if link_field value is falsy
let text_to_show = value => {
return value ? value : '-';
};
// this function will be called from the Form's onload/onrefresh
// to fetch the value from the DB and render the Link field title initially
let init_field_title = (frm, link_field_name) => {
if (!frm.fields_dict[link_field_name].value)
return;
frappe.db.get_doc(
frm.fields_dict[link_field_name].df.options,
frm.fields_dict[link_field_name].value
).then(result => {
render_field_title(frm, link_field_name, text_to_show(result.title));
});
};
// the render function itself, just to be DRY
let render_field_title = (frm, title, text) => {
let field = frm.fields_dict[title];
field.label_span.innerHTML = `${__(field._label)} - <b>${text}</b>`;
};
frappe.ui.form.on('Target Doctype Here', {
refresh: frm => {
init_field_title(frm, 'link_package');
},
// update the link field title on the selection change
link_package: frm => {
let field = 'link_package';
frappe.db.get_doc(frm.fields_dict[field].df.options, frm.fields_dict[field].value).then(result => {
render_field_title(frm, field, text_to_show(result.title)); // my Link fields have a display field named 'title'
});
},
});
This hack pounds at the database mercilessly if there’s a lot of Link fields on the form, unfortunately. A better (not really better, just less db-expensive) way would have been to monkey-patch the Awesomeplete object to intercept the key-value data, but reeeeeeeeeealy don’t want to go there
I hope the devs will find some time to remedy this DDL oddity.
I have a query
I have two doctypes one is Pryto projects and other is Site Visits_1 so I want to know how to get the details from Pryto projects and display it in Site Visits_1.
@joelios but with the workaround (product_name field) you have the same informations…why is that not ok for you?
That’s not Ok because if you change the value of the field in the source doctype it won’t change in the the linked doctype unless you go edit that document and resave.
I know it’s an old thread but it’s been 3 years and there’s no real solution for this yet. This could be easily done with a join SQL query, but the list view is a core component of Frappe and I’m not yet very familiar on how it’s built to make changes in the core functionalities.