Printing all data from custom field

I want to add shipping address + contact to my Purchase Order. I have it all figured out (I think) with custom fields and print forms, but I cannot get the full value/data of the Custom Field to show in the final printed PO.

step1 - I have made two Custom Fields, both DocType Links for Contact and Address.

step2 - Then, in my Purchase Order, I am able to select from available Addresses and Contacts to propogate the fields – so far so good.

step3 - Then, I made a Print Format that has both these Custom Fields added.

step4 - Finally, when I print, it shows the two Custom Fields, but it only shows the title/heading of those fields, NOT the full data. How do I print the data that is held within the fields I selected?

This is the only roadblock to me actually using ERPNext for real. Thanks!

I put images of the 4 steps at http://imgur.com/a/B9a7S since I cannot upload images here.

@ryarrow I tried it on a test system and it worked for me. Maybe you are doing something else, or checking the wrong format?

@rmehta - I’m using the VM downloaded from the website.

In the first picture - http://i.imgur.com/Mm2qnhc.jpg - it is showing the Address Title on the final PDF output … I want it to show all the data contained within that address record. The address record has city, street, etc. and I want that to show on the PDF, not just the title of the address record. Does that make sense?

The address data would be a different field, make sure you are showing it.

Show it how? I don’t see anything in the Print Format Builder to get the address data. The custom link field I created shows up in the Print Format Builder but I don’t see any way to get the address data over from the custom field … sorry, confused :smile:

Seems confusing to me either. What you are asking should work out of the box (I just tried it). Maybe you created 2 fields with the same label?

I refreshed the PO form back to defaults and tried again. I customized the form, made a single field (Link to Address). When I add the field to the print form, it still only shows the title “XYZ-Shipping” and not the actual address. I can’t make it work :frowning:

I’m trying to do the same thing and I think I’ve found a way. It is more complicated, but it is somewhat working for me.
The short answer is that you need to add custom scripts that will populate other fields:

  1. Create your custom fields that are links for contact and address.
  2. Create additional custom fields for the Address Line 1, Address Line 2, City/Town, State, Postal, etc. The data type is Data, and make them hidden.
  3. Create a custom field that is a Small Text that will hold the full address (“supplier_address”)
  4. Create a custom script for the Purchase Order form and use the following lines of code:

cur_frm.add_fetch(“address__ship_to_”, “address_line1”, “shipping_address_line1”);
cur_frm.add_fetch(“address__ship_to_”, “address_line2”, “shipping_address_line2”);
cur_frm.add_fetch(“address__ship_to_”, “city”, “shipping_address_city”);
cur_frm.add_fetch(“address__ship_to_”, “state”, “shipping_address_state”);
cur_frm.add_fetch(“address__ship_to_”, “country”, “shipping_address_country”);
cur_frm.add_fetch(“address__ship_to_”, “pincode”, “shipping_address_postal”);

//cur_frm.add_fetch(“attn_person”, “email_id”, “attn_email”);

frappe.ui.form.on(“Purchase Order”, “onload”,function(frm)
{
var text = frm.doc.shipping_address_line1 + ‘\n’;
if(frm.doc.shipping_address_line2 != ‘’)
{
text +=frm.doc.shipping_address_line2 + ‘\n’;
}
if(frm.doc.shipping_address_city != ‘’)
{
text +=frm.doc.shipping_address_city + ‘\n’;
}
if(frm.doc.shipping_address_state != ‘’)
{
text +=frm.doc.shipping_address_state + ‘\n’;
}
if(frm.doc.shipping_address_country != ‘’)
{
text +=frm.doc.shipping_address_country + ‘\n’;
}
if(frm.doc.shipping_address_postal!= ‘’)
{
text +=frm.doc.shipping_address_postal+ ‘\n’;
}

frm.set_value(“shipping_address”,text);
});

The explanation is as follows: I use the add fetch to grab all the address details and put them in the hidden fields.
Then, on any sheet update, I grab all those fields and fill them into the shipping address text.

This is a really ugly way of doing it, but I’m just getting started with the coding and am not familiar with all the functions.

Hope this helps.

1 Like

@Ben_Cornwell_Mott - thanks for chiming in. I ended up doing very similar things to solve my problem. I did steps 1 and 2 and then similar custom scripts like you did in step 4. I handled step 3 and the building of the final address in a new print format using custom HTML so that it shows when I generate the PO PDF. Basically, we did the same thing but through equally roundabout means. This was really annoying to figure out at first, but I learned a lot along the way. My custom HTML:

{{ doc.customer }}<br>
Attn: {{ doc.ship_to_name }}<br>
{{ doc.ship_to_address_line1 }}<br>
{% if doc.ship_to_address_line2 %}{{ doc.ship_to_address_line2 }}<br>{% endif -%}
{{ doc.ship_to_city }}, {{ doc.ship_to_state }} {{ doc.ship_to_zip }}<br>
{% if doc.ship_to_phone %}{{ doc.ship_to_phone }}<br>{% endif -%}
2 Likes

Thanks for the tip! I think I was able to get it working really well. It took quite a bit of searching through the documentation, but now this solves all the problems. To explain: when the supplier_address is updated, the frappe.call funciton is used, which gets the address information and allows it to be formatted. I think this is a much more elegant solution than what I was doing before.

frappe.ui.form.on("Purchase Order", "supplier_address",  function(frm){  frappe.call({
        "method": "frappe.client.get",
        args: {
            doctype: "Address",
            name: frm.doc.supplier_address
        },
        callback: function (data) {
            frappe.model.set_value(frm.doctype,frm.docname, "supplier_address_display",
                data.message.address_line1
                + (data.message.address_line2 ?
                    ("\n" + data.message.address_line2) : "")+ (data.message.city ?
                    ("\n" + data.message.city) : "")+ (data.message.state ?
                    (", " + data.message.state) : "")+ (data.message.pincode ?
                    (" " + data.message.pincode) : "")+ (data.message.country ?
                    ("\n" + data.message.country) : ""))
        }
    })});
4 Likes