Question about the usage of

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
Have I done something wrong?

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

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



Hi Fresthy

The last console.log(price_list) return undefined is correct because 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.



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);