HELP with (Client Script) Petty Cash expense not more than 10K

Hi Everyone,

I have a doctype called Cash Book in which users make entries of daily expense.
I want that if someone tries to enter a entry of more than 10,000 then it will not allow user to save the document.

I guess it can be sorted via client script, can someone explain the solution ?

 frappe.ui.form.on('Cash Book', {
   validate: function(frm) {
    // Directly access the numeric value of 'expense' field
    let expenseValue = frm.doc.expense;

    // Check if the entered expense is greater than 9,990 INR
    if (expenseValue > 9990) {
        frappe.msgprint(__('Expense cannot exceed 10,000 INR.'));
        frappe.validated = false;  // Prevent the document from being saved
    }
  }
 });

I tried this but its not working.

Thank You

Try this script

frappe.ui.form.on('Cash Book', {
    validate: function(frm) {
        if (frm.doc.expense && frm.doc.expense > 10000) {
            frappe.msgprint({
                title: __('Validation Error'),
                message: __('Expense cannot exceed 10,000 INR.'),
                indicator: 'red'
            });
            frappe.validated = false;
        }
    }
});

Hi there,

One thing to think about: client scripts never provide security. With a small amount of knowledge, a user could bypass this restriction and submit an expense of any amount.

If you’re just looking to remind your accounts team of this rule, this script is probably fine. If you actually want to prevent the expense from being booked, however, you should use a server script.

I guess i need to enable the server script as i’m using erp hosted via frappe cloud.

script not working

i used this -

frappe.ui.form.on('Cash Book', {
validate: function(frm) {
    // Check if the entered expense is greater than 10,000
    if (frm.doc.expense > 9,990.000) {
        frappe.msgprint(__('Expense cannot exceed 10,000.'));
        frappe.validated = false;  // Prevent the document from being saved
    }
}
});

and it does gives the pop up that the amount exceed, but the issue is it does not allow me to save any amount.

I tried with that script and it is working as expected.

frappe.ui.form.on('Cash Book', {
    validate: function (frm) {
        // Check if the entered expense is greater than 10,000
        if (frm.doc.expense > 10000) {
            frappe.msgprint(__('Expense cannot exceed 10,000.'));
            frappe.validated = false;  // Prevent the document from being saved
        }
    }
});

It’s not working from my side, i dont know why, also the expense is in a child table of the Cash Book doctype.

Can you share the structure of the Doctype? Parent / Child ?

Cashbook Parent table-

Child Table

Hi @rs115199789 ,

frappe.ui.form.on('Cash Book', {
    validate: function(frm) {
        // Iterate through each row in the child table
        frm.doc.data_aez3i.forEach(row => {
            if (row.expense > 10000) {
                frappe.throw(__(`Expense amount in row ${row.idx} cannot exceed 10,000.`));
            }
        });
    }
});

I was thinking the same as my old scripts run with that name.

Thank you so much for your help :slight_smile: