Whitelisting Python function


I feel I must be missing something obvious here. I have a custom app called email_digest, and inside of it is this simple python script:

#Embedded file name: /home/erpnext/frappe-bench/apps/email_digest/email_digest/send_sms.py                                                                                                                         
import sys, frappe, messagebird
from frappe import sendmail

def fire():
    client = messagebird.Client('live_CodeGoesHere')
    msg = client.message_create('FromName','0741234567','This is a test', {'test' : True})

This script works with bench execute email_digest.send_sms.fire

The script has also been added to email_digest.egg-info/SOURCES.txt

It’s whitelisted in the same way as other scripts I’ve seen in ERPNext.

I have a custom script which goes as follows:

frappe.ui.form.on("DoctypeNameHere", "refresh", function(frm) {
    frm.add_custom_button(__("Send SMS"), function() {

When pressing the button, I get this error in my browser console:

TypeError: frappe.email_digest is undefined

What am I doing wrong? Why can I not fire this python script from javascript?

Once I get this working, I can easily customize it with arguments containing the variables I need on both the python and javascript ends, I’m just trying to get a very basic form functional. Am I calling it wrong from Javascript, do I need to do something more in Python, or is it something else entirely?

Hi @JamesE,

You are not calling python function correctly from the javascript, you need to write frappe.call inside the javascript to call the python function.

For example check below links

Thanks, Rohit

Hi @rohit_w,

Thank you. Using the javascript you linked as a model, I ended up with this:

frappe.ui.form.on("DoctypeNameHere", "refresh", function(frm) {
    frm.add_custom_button(__("Send SMS"), function() {
            callback: function(r){

It works perfectly, and the args and callback portions seem very straightforward to use to expand this into covering all the functionality we need.

This topic can be closed now, if someone wants to do it.

Thanks again,

1 Like