Issue with javascript

Hi everyone, I have a question if someone here already had a issue with js in frappe, for example when I load a field based in another just like in Production Order when you choose a product and it brings the BOM well I’m with a issue when I choose something I need to bring other thing to fill a field well like add_fetch but sometimes this work and sometimes not and it’s not cache anyone already had this problem. Thanks for advance.

@Thiago_Henry,

can you share your code?

Thanks,
Makarand

Sure. First this one. When I change the production item I want to bring uom but sometimes bring and sometimes not

production_item:function(doc, cdt, cdn) {
    frappe.db.get_value("Item", { name: cur_frm.doc.production_item },
    ["stock_uom","item_group"],
    function(r) {

        if (r.item_group == "Sub Assemblies"){
            frappe.call({
                method: "erpfoa.manufacturing_foa.doctype.production_order.production_order.st_from_scrap",
                args: {"production_item": cur_frm.doc.production_item},
                callback: function(data) {
                    data.message;
                }
            });
        }


        cur_frm.doc.item_group = r.item_group
        cur_frm.doc.stock_uom_1 = r.stock_uom;
        cur_frm.doc.quantity = cur_frm.doc.quantity | 0;
        cur_frm.doc.uom = r.item_group == "Products" ? "Box" : r.stock_uom;
        cur_frm.cscript.reload_uom_conversion_factor( doc, cdt, cdn );

        cur_frm.cscript.setup_warehouses();
        cur_frm.cscript.setup_origin_production_order(r.item_group);
        if(r.item_group == "Raw Sub Assemblies")
        {
            cur_frm.set_df_property("origin_production_order", "hidden", true);
        }
    });
},

I have other but is too big. Thanks for support

I almost forget it

        reload_uom_conversion_factor : function( doc, cdt, cdn  ){
            setTimeout( function(){
                if( cur_frm.doc.production_item && cur_frm.doc.uom ) {
                    frappe.call({
                        method: "erpnext.stock.get_item_details.get_conversion_factor",
                        args: {
                            item_code: cur_frm.doc.production_item,
                            uom: cur_frm.doc.uom
                        },
                        callback: function(r) {
                            if(!r.exc) {
                                cur_frm.set_value("uom_conversion_factor", r.message.conversion_factor);
                            }
                        }
                    });
                }
            }, 500)
        },