How to change a field value via custom script when grand_total changes


I’m trying to trigger an automatic filling up of a custom field when the grand total is changing by using the following code

frappe.ui.form.on('Sales Invoice', 'grand_total', function(frm){
    ---code here----
    frm.set_value("in_greek_words", "custom string");

if I set it onload or refresh for the whole invoice it works, but it won’t trigger for when grand_total value changes. Any ideas? Thanks in advance

@gabtzi, current the event is triggered only for non-readonly fields. But if you need get in words in greek, fork this project, adapt as you needs, and make a pull request

Unfortunately it’s still beyond me to make the transformation from Javascript to Python, I’ve only touched python like 3-4 times in ERPNext to approach some bugs.

I’d very much like to work on it as a future enhancement but it’s not something I’d be able to pull off easily. The Greek language is actually pretty complex when it comes to the correct usage of the the words when translating a number because it has cases, genders and declensions depending on whether we’re on hundreds, thousands, millions and billions.
Also it’s different if we’re talking about money and different if we’re talking about plain numbers.

That’s why I worked on it on a very small scale like up to 9999,99 for my current custom needs and I left the custom field open to editing so it can be entered manually too. However I wanted to also enter a value if it was <9999,99 so that a person wouldn’t forget to change it.

I’ll experiment a bit more on it tomorrow to see if I can make it work for readonly fields too since you suggested it doesn’t work because it’s not implemented like that.

@gabtzi, we are here if do you need some tips!

Anyways, for now I just worked around the issue by using MutationObservers until I find a more suitable solution

var grandTotalObserver = new MutationObserver(function(mutations) {
    mutations.forEach(function(mutation) {
        cur_frm.set_value("in_greek_words", inWords(cur_frm.doc.grand_total));

var target=document.querySelector('div[data-fieldname="grand_total"] .control-input-wrapper .control-value');
var options = {
    attributes: true,
    characterData: true

grandTotalObserver.observe(target, options);

This topic was automatically closed after 32 hours. New replies are no longer allowed.