Function not working in callback


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 callback.
its working fine when i call it after

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>";
        method: "erpnext.projects.doctype.projects.projects.get_colors",
        args: {
            status: data.Status
        callback: function(response) {
             var r = response.message;
                //Not working

        //Working fine
	    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 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 =)


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

1 Like