Custom Script help: evaluating values of child table

Hi can someone point me in the right direction? Have gone through the different client scripting example pages here and here. As well as forums. But need more guidance.

I want to create a script to evaluate the rate values of each item row in the sales_order_item table if the item_code is equal to some specific values. I want to do this evaluation at validate event.

Any basic help would be appreciated!

In JS you can do it like this.

for(var i = 0;i <cur_frm.doc.items.length;i++){
if(cur_frm.doc.items[i].rate == 200){
console.log(“do something”);
}else{
console.log(“dont”);
}
}
}

In Py you can do it like this:

for item in self.items:
if item.rate == 100:
#do something here

just fix the tabs heheh

1 Like

Thanks @Justine_Jay_Caneza. That helped me figure it out. Sharing code here on how to set a global price limit for sales order items that effectively takes priority over pricing rules.

   frappe.ui.form.on('Sales Order', 'validate', function(frm) {
      for(var i=0;i < cur_frm.doc.items.length; i++){
        if(cur_frm.doc.items[i].rate < 1000 && cur_frm.doc.items[i].item_code == 'WIDGET001'){
          msgprint('Price is below floor price! Please seek approval.');
          frappe.validated=false;
        }
      }
    });
2 Likes

Happy it helped :smiley:, kindly mark this thread done :+1:

I was thinking about that. But don’t see how I can close this thread; don’t think I have privileges to close?