Get items from other doctype

I have a custom doctype vehicle info.

The doctype is linked in a sales order.

Now I want to display all the field from this doctype in a text field on the sales order so I know what are the fields.

So I create a other smalltext field that I want to fill like the customer address in a sales order
frappe.ui.form.on(“Sales Order”, {
refresh: function(frm) {

frm.add_fetch("customer_vehicle", "v_annee", "vehicletext");
text1 = frm.doc.customer_vehicle.v_annee;
frm.add_fetch("customer_vehicle", "v_model", "vehicletext");
var res = text1.concat(frm.doc.vehicletext);
frm.set_value("vehicletext", text1);


And this doesnt work. Only last field is displayed.
What would be the other way of fetching multiple items and merging into one string.

you want all the info in one single text field?
if yes, use multiline string in js and use jinja placeholders to populate values into that string and then set that string value into your text field,

screenshots would help to get little more context

I want to do like the address field


using multi line strings + jinja placeholders and html for formatting will let you fetch data from a doc with linkfield and populate the target like this

maybe there is better way,

this is a bit like Chinese to me.
I’ll try to search for those terms but if you have more details on jinja that would be great.
I would like to be able to do that in a custom script so this way there is no major modification to erpnext

in js, after fetching the data with link field( say its in vehicle_info object ), do

adress_var = `  {{vechicle_info.field_1}} <br> {{vehicle info.field_2}} `  

keep adding fields until u have all of that data in address_var and then, replace field_1 and so with fieldnames you want to fetch from the source doc where address is

frm.set_value("vehicletext", address_var);

pair it with appropriate triggers, and you should be able to do what you want

How do you fetch the data and set in the the object?

Here is what I did:
frappe.ui.form.on(“Sales Order”, {
customer_vehicle: function(frm) {
var adress_var = “Testing123”;
adress_var = {{customer_vehicle.v_annee}} <br> {{customer_vehicle.v_model}};
frm.doc.vehicletext = adress_var;

you dont need to actively fetch data, thats what the linkfield / linking does.
once a customer is selected, all data in the customer doc will be in customer_fieldname, use that as object name where i used vehicle_info

It doesnt work. I’m not able to access the “v_annee” and v_model inside my form. It’s empty…
frappe.ui.form.on(“Sales Order”, {
refresh: function(frm) {
var adress_var = “Testing123”;
adress_var = customer_vehicle.v_annee;
frm.doc.vehicletext = adress_var;

provide a screenshot of your source doc, where this v_annee is,

Thanks to @neerajvkn

This is what I ended with and it’s now working

frappe.ui.form.on("Sales Order", {customer_vehicle: function(frm) {
            "doctype" :"VehicleInfo",
            "name" : frm.doc.customer_vehicle
            var vdata = "";
            if(r.message.v_annee != null)
                vdata += `${ r.message.v_annee} `
            if(r.message.v_make != null)
                vdata += `${ r.message.v_make} `
            if(r.message.v_model != null)
                vdata += `${ r.message.v_model} `
            if(r.message.v_engine != null)
                vdata += `${ r.message.v_engine} `
            if( r.message.v_color != null)
                vdata += `${ r.message.v_color}`
            vdata += `
Vin: `
            if( r.message.v_vin != null)
                vdata += `${ r.message.v_vin}`
            vdata += `
Plaque: `   
            if( r.message.v_plate != null)
                vdata += `${ r.message.v_plate}`
            vdata += `
Km: `
            if( r.message.v_odo != null)
                vdata += `${ r.message.v_odo}`