How to return result from Promise when call frappe.call


frappe.listview_settings['Customer'] = {
    formatters: {
        mobile_no: function(value, field, doc) {
          let address =  frappe.call({method: 'my_app.api.customer.get_customer_contact',
               args: { name: doc.customer_name}}).then(function(result) {
                return result.message;
             });
             const printAddress = async () => {
                const a = await address;
               return a
              };
             return printAddress()
            }
    },
    
}

I always return [object Promise], how to return the result

@treeem You are very close to the solution!

frappe.call({method: 'my_app.api.customer.get_customer_contact',
   args: { name: doc.customer_name}}).then(function(result) {
}).then(r => { `more stuff here` })

I prefer using frappe.xcall because it has a less verbose signature and also returns a promise.

frappe.xcall(
  'my_app.api.customer.get_customer_contact',
  { name: doc.customer_name}}).then(function(result) {
).then(r => { `more stuff here` })

I have tried, but return undefined

frappe.listview_settings['Customer'] = {
    formatters: {
        mobile_no: function(value, field, doc) {
            frappe.call({method: 'wi_app.api.customer.get_customer_contact',
            args: { name: doc.customer_name}}).then(function(result) {
            }).then(r => { return r.message.phone })
     },
       // return "val_here" 
      // if I put above `return`  it show up, I want to return from call back to here.
    }
}

Instead of doing a .then(), try giving the return within the callback parameter. Also try adding the async: false parameter if you get a return object promise.

can you guide with sample of your approach , please

Thanks

This looks like a bad idea in the first place, you shouldn’t be having a frappe.call in formatters.
Imagine the number of db calls on a list view with 500 documents!

Rather, whatever details it is, have it stored in the customer itself and show it in the list view.

2 Likes