Cur_frm.save(); It is saving and does not continue the remaining code

Hello;
When I am using cur_frm.save(); in .js script, it is doing save for the document and does not continue executing the remaining code in the script.
I need to do save for what is existed in the form and then executing the remaining code and then I need to do location.reload().
If I did not do save in the beginning, the old data will appear in the fields after doing location.reload().
What is the solution to be able to save and continue the code?
Regards
Bilal

Hi @bghayad,

Can you please post your code, it will be easier to understand your issue and help you ?

Be aware that cur_frm is deprecated.

frappe.ui.form.on(‘R7 Yearly Declaration For Employees That Leaved’, {
refresh: function(frm) {

    },
    financial_year: function(frm) {
            if (frm.doc.__islocal){
                    cur_frm.save();
            }
    },
    button_leaved_employees: function(frm) {
            if (frm.doc.financial_year){
                          cur_frm.save();
                  }
                    frappe.call({
                            method: "erpnext.hr.doctype.r7_yearly_declaration_for_employees_that_leaved.r7_yearly_declaration_for_employees_that_leaved.get_leaved_employees",
                            args: {
                            parent_id: cur_frm.doc.name,
                            financial_year: cur_frm.doc.financial_year
                            },
                            callback: function(r) {
                            location.reload();
                            }
                    });
                    }
            }

});

Regarding to the code: button_leaved_employees: function(frm), when we run cur_frm.save(); in the part:

            if (frm.doc.financial_year){
                          cur_frm.save();
                  }

It does not continue to run the frappe.call and here is the problem.
Regards
Bilal

Hi @bghayad,

You need to remove the end bracket just after “cur_frm.save()” in the “button leave employee” function.
It stops the execution.

Else you need to use an “if/else if/else” logic.

Hope this helps.

I removed the bracket and it is the same.
It is saving and not continue.
The current updated script as below:

frappe.ui.form.on(‘R7 Yearly Declaration For Employees That Leaved’, {
refresh: function(frm) {

    },
    financial_year: function(frm) {
            if (frm.doc.__islocal){
                    cur_frm.save();
            }
    },
    button_leaved_employees: function(frm) {
            if (frm.doc.financial_year){
                    cur_frm.save();
                    frappe.call({
                            method: "erpnext.hr.doctype.r7_yearly_declaration_for_employees_that_leaved.r7_yearly_declaration_for_employees_that_leaved.get_leaved_employees",
                            args: {
                            parent_id: cur_frm.doc.name,
                            financial_year: cur_frm.doc.financial_year
                            },
                            callback: function(r) {
                            location.reload();
                            }
                    });
            }
    }

});

Regards
Bilal

What do you mean by continue? Are you looking to do something like set_route?

I mean: executing the remaining code in the method.

Regards
Bilal