ERPNext Foundation ERPNext Cloud User Manual Blog Discuss Frappé* Donate

Sales Incentive Custom Script Not Working


Referring to the custom script examples, I used the sales incentive example and then I made some adjustments (only the amount of the incentive percentage and grand total of the sales order)

This is the script

// calculate sales incentive
frappe.ui.form.on(‘Sales Order’, {
validate: function(frm) {
// calculate incentives for each person on the deal
total_incentive = 0
$.each(frm.doc.sales_team, function(i, d) {
// calculate incentive
var incentive_percent = 1;
if(frm.doc.base_grand_total > 10000) incentive_percent = 1.5;
// actual incentive
d.incentives = flt(frm.doc.base_grand_total) * incentive_percent / 100;
total_incentive += flt(d.incentives)
frm.doc.total_incentive = total_incentive;

But it doesn’t seem to work. It does not calculate even after I have submitted the Sales Order.