I want to display a message in onrefresh, but after inserting, the message appears twice

I want to display a message when opening a document, so I wrote it in onrefresh. When opening an existing document, the message only shows once. However, after creating a new document, I noticed (by logging) that onrefresh is triggered twice.


How should I fix this issue?

Please use it.

frappe.ui.form.on('Test Default Value', {
    refresh: function(frm) {
        if (!frm.is_new() && !frm.message_thrown && frm.doc.percent == 0) {
            frm.message_thrown = true;
            frappe.throw("Percent must be greater than 0");
        }
    }
});

Then reload Ctrl+Shift+R and check it.

1 Like

Thank for solution. but the solution does not work because if there’s a change to an item that should also trigger an error message, it will not trigger. Entering onrefresh twice after creating an item is the correct behavior, right?

Then you use your script only because this problem will not be solved on refresh because it will pass the message twice.