Confirmation box do not stop for response

What is wrong with following code. I am trying to get user confirmation if the payment entry is duplicate on same date?

frappe.ui.form.on("Payment Entry", "validate", (frm) =>{
        if(frm.doc.status !="Cancelled"){            
     
          frappe.call({
              method: "frappe.client.get_value",
              args: {
                  "doctype": "Payment Entry",
                  "filters": {"party_name": frm.doc.party, "posting_date": frm.doc.posting_date},
                  "fieldname": 'party_name'
              },
              callback: async function(data) {
                  if(!$.isEmptyObject(data.message)) 
                      await showConfirmationDialog();
              }       
      });
  }
});


function showConfirmationDialog(){
      return new Promise((resolve,reject) => {
                          frappe.confirm(
                              'The Payment on same date already exist.Do you want to continue?',
                              () => resolve(),
                              () => reject("frappe.validated = false")
                          );
      });
}

After some rest. I refactored this code. and avoided this callback hell. and successfully resolved my issue

@zulfi007- may you share the refactored code? I

    if (frm.doc.__unsaved && frm.doc.__unsaved===1) {
        const data = await frappe.db.get_value("Payment Entry", {
                "party_name": frm.doc.party,
                "posting_date": frm.doc.posting_date
            },
            ['party_name','status']
        );
            
        if (!$.isEmptyObject(data.message)) {
            let promise = new Promise((resolve, reject) => {
                frappe.confirm(t"Duplicate payment on same date. Do you want to continue",
                    () => resolve(),
                    () => reject()
                );
            });
            await promise.catch(() => frappe.throw());
        }
    }
});
1 Like

@zulfi007- thank you very much. greatly appreciated