Try ERPNext Buy Support Partners Foundation Foundation Members

If else doesnt work

I was trying to do a if else statement, that if customer field is empty then alert me and else do the frappe.call. Am i doing something wrong? Please help me.

I use this code

function(){
if (frm.doc.customer === “”){
alert(“Working”);
}

else{
frappe.call
}
}

This is the frappe.call

function get_items_from_bom(bom) {
      frappe.call({
        "method": "frappe.client.get",
        "args": {
            "doctype": "BOM",
            "name": bom
        },
        "callback": function(response) {
             var bom = response.message;
             bom.items.forEach(function (item) {
                 var child = cur_frm.add_child('equipment');
                 frappe.model.set_value(child.doctype, child.name, 'item_code', item.item_code);
                 frappe.model.set_value(child.doctype, child.name, 'qty', item.qty);
    	     frappe.model.set_value(child.doctype, child.name, 'selling_rate', item.selling_rate);
             });
    	
             cur_frm.refresh_field('equipment');
         }
       });

You need to accept frm as a parameter to your function to use it in the if condition below.
Like so:

function (frm) {
    if (frm.doc.customer) {
    ---
}

Thank you! Just a question why doesn’t it accepts === “”? and only acceps == null

function(frm){
if (frm.doc.customer == null){
alert(“Working”);
}

else{
frappe.call
}
}