First javascript test for a new app

Hi,

I’m trying to create a new App for ERP Next call Work Order 2. In the page I’ve create a link with the Customer. Now I’m trying to fetch info from the customer and put it in field call Shipping Address. So base on the Librairy exemple, I create that script :

frappe.ui.form.on("Work Order 2", "Customer",
function(frm) {
    frappe.call({
        "method": "frappe.client.get",
        args: {
            doctype: "Customer",
            name: frm.doc.customer
        },
        callback: function (data) {
            frappe.model.set_value(frm.doctype,
                frm.docname, "shipping_address",
                data.message.territory)
        }
    })
});

For testing purpose I try to put the value of the territory field in shipping_address but it’s not working. Any idea why?

Here the error code I get from Frappe :
Message
Customer Customer not found
Not found

Thank you

Ok I found my error the Name args was customer with a C capital. since it’s named “Customer”.

In the line, “Customer” need to be the name of the field that you have in the doctype. Normally is in lower case. try it and let me know.

thank you geekroot. It was my error :
args: {
doctype: “Customer”,
name: frm.doc.Customer

By writing it with a C I correct it, since my field in the doctype is writing Customer.

Ok, now for some more complex stuff. I need to fetch a shipping address from the customer. I should be able to do that by using the customer field and the address_type filed from the Address Doctype.

I suppose I need to change this part of the code :

args: {
            doctype: "Customer",
            name: frm.doc.customer
        } 

For the doctype arg : probably “Address” and then should I just add address_type: “Shipping” and customer: frm.doc.Customer so it look like that :

args: {
            doctype: "Customer",
            address_type: "Shipping"
            customer: frm.doc.Customer
            }

What do you think?

Hum look like this don’t work :

frappe.ui.form.on("Work Order 2", "Customer",
    function(frm) {
        frappe.call({
            "method": "frappe.client.get",
            args: {
                doctype: "Address",
                customer: frm.doc.Customer,
                address_type: "Shipping"
            },
            callback: function (data) {
                frappe.model.set_value(frm.doctype,
                    frm.docname, "shipping_address",
                    data.message.address_line1)
            }
        })
    });

Do somebody have a idea?

Thank you

Call your args with filters:

args: {
  doctype: "Address",
  filters: {customer: frm.doc.Customer, address_type:"Shipping"}
}

Thank you @rmehta!!!