Question about the usage of frappe.call

I tried to create custom script to pull Price List object.
The issue is while the first 2 console.out provides result, the last show undefined.
Based on the order of the printed output, looks like the last console.out was called before frappe.call
Have I done something wrong?

frappe.ui.form.on("Item", {
    refresh: function(frm) {

	var price_list;

	frappe.call({
        method: "frappe.client.get",
        args: {
            doctype: "Price List",
            name: "Standard Selling",
        },
        callback(r) {
            if(r.message) {
                price_list= r.message;
                console.log(price_list.name);
            }
	    console.log(price_list);
        }
    });

	console.log(price_list);

    }
});

Hi Fresthy

The last console.log(price_list) return undefined is correct because frappe.call is ajax function must run done then return result. => so console.log(price_list) must in callback.

Hi vinhnguyent090,

Thanks for your reply.

Is there any other ways to get doc without ajax call?

I want to create a script to automatically update selling rate based on item.standard_selling_rate and it needs to retrieve a few doc (Item List, Item Price) for the update.

Thanks

Hi

I just know If is link field, when change you can get this doc
example when change purchase_order in Purchase Invoice form

frappe.ui.form.on("Purchase Invoice", {
 purchase_order: function(frm, cdt, cdn){
        var  doc = frappe.model.get_doc(cdt, cdn);
}
}