Apply "in_words" function with Client Scripts

Hello everyone,
I add “in_words” field in Payment Request doctype. I use client script to call money_to_words function in utils of frappe but it doesn’t work.

I use form option and this is my js code:

frappe.ui.form.on('Payment Request', {
     onload: function (frm) {
        frappe.call({
            method: "frappe.utils.data.money_in_words",
            args: {
                "number": frm.doc.grand_total, 
                "main_currency": "VND"
            },
            callback: function (inWords) {
                if (inWords){
                    frm.set_value("in_words", inWords.message);
                    frm.refresh_field('in_words');
                }
            }
        })
    }
})

What wrong with my code ??
Regards.

Hi @Th_Nguy_n_Phu,

I think, It seems that the frappe.utils.data.money_in_words function is not whitelisted.

Whitelisting is a security feature that restricts access to server-side functions. You need to whitelist the function before you can use it in your client-side scripts.

Thank You!

1 Like

Thanks for your suggession.

I modified a new “money_in_words” function in server-scripts for Payment Request doctype.

I have some stucks:

  • how to get information of current payment request ?
  • path of this function to pass method argument ?

You have any idea.

Regards.

Hi @Th_Nguy_n_Phu,

Syntax:

if doc.grand_total:
    doc.in_words = frappe.utils.money_in_words(doc.grand_total, "VND")

I hope this helps.
Thank You!

Oh thanks for your code and apologize for replying lately.

I want to pass Payment Request ID automation, in my code is “docid”.

Regards

We just share the syntax.
Please set your code according to.

what is docid?
when you print then show none.

So first define the docid and then apply your scenario.

Thank You!

After I had researched in community, I knew that: only use script API in server scripts (can’t use “import” syntax and “doc” is representative for “cur_frm” → right ?)

Finally, I try this code but it is’t working

inWords = frappe.utils.money_in_words(doc.grand_total, "VND")
frappe.db.set_value("Payment Request", doc.name, "in_words", inWords)

This is my setting.

Ps: I deployed by docker and added server_script_enabled config in server

Regards


# Get the document to be updated
doc = frappe.get_doc("Doctype Name", "Document Name")

# Update the field value
frappe.db.set_value("Doctype Name", "Document Name", "field_name", "new_value")

# Save the document
doc.save()

More details for check it.
https://frappeframework.com/docs/v14/user/en/api/database

Thanks You!

1 Like

Thanks for your reply

doc = frappe.get_doc("Doctype Name", "Document Name")
frappe.db.set_value("Doctype Name", "Document Name", "field_name", "new_value")

Both of them are passed by specific detail “Documet Name” argument, but I want to pass it automatically and update multiple records into database.
You have any solution

Regards

If you did not add the add this and check it.