Function not working in frappe.call callback

Hi,

in js of query report, i am calling an api which returns color code,
but and i’ve a function named fun which is responsible to color the row.
but unfortunately function is not working when i call it in frappe.call callback.
its working fine when i call it after frappe.call

here is my code, i’ve added comments to understand clearly.

frappe.query_reports["Test"] = {

    "formatter": function(value, row, column, data, default_formatter) {
    row = default_formatter(value, row, column, data);
    value = default_formatter(value, row, column, data);
    
    var fun = function(color){
	    value = "<div style='background-color:"+ color +";'>"+ value +"</div>";
	}

    frappe.call({
        method: "erpnext.projects.doctype.projects.projects.get_colors",
        args: {
            status: data.Status
        },
        callback: function(response) {
             var r = response.message;
                //fun(r);
                console.log(r);
                //Not working
                fun("#110000");
        }
	});

        //Working fine
        //fun("#110000");
        
	    return value;
	}
}

It works, it just gets executed after formatter() function finishes running and thus has no effect on it, because the callback gets executed asyncronously. Add async: false, to the frappe.call() parameters.

1 Like

Thanks buddy @igrekus, i’ve just wasted an hour in this. :stuck_out_tongue:

We all have been bitten by js async trickery at some point in our careers =)

2 Likes

Its working fine now, but its take about 5 secs to load the report.

1 Like