How to program a button field type using server side?

Greetings, everyone :wave:

I have a doctype named Google Translator. Inside this doctype, I added a button field type named btn. Then, I program it to do a task using client side script:
frappe.ui.form.on(“Google Translator”, “btn”, function (frm) {});

And it worked fine.

My question here is, how to accomplish this task using Python (server side script) ?
In other words, what is the python equivalent code of the the above JS code?


Write a python method (it could be whitelisted) and call the method from inside the js script on callback perform needed client tasks

1 Like

I’m reading about
Thank you

It works perfectly :grin:

.js Code:

// Omar M Shehada
frappe.ui.form.on('Google Translator', {
	refresh: function(frm) {
		frm.set_intro('Enter a text -> Pick up a language to translate to -> Hit Do Translate! -------> **You need to be ONLINE**')

		// Making edits on the css level

	btn: function(frm) {{
			doc: frm.doc,
			method: 'frm_call',
			args: {
				msg: 'Hallo!'
			freeze: true,
			freeze_message: __("Translating..."),
			callback: function(r) {


// Making edits on the css level
function set_css(frm) {
  document.querySelectorAll("[data-fieldname='text']")[1].style.color = '#202020'
  document.querySelectorAll("[data-fieldname='text']")[1].style.fontWeight = 'bold'
  document.querySelectorAll("[data-fieldname='text']")[1].style.background = '#12ff21'

.py Code:

import frappe
from frappe import _
from frappe.model.document import Document
from googletrans import Translator

class GoogleTranslator(Document):
	# Keep in mind that this doctype needs to be connected to the Internet
	def frm_call(self, msg):
		import time
		trans = Translator()
		text = self.text

			out = trans.translate(text, dest=self.pick_a_lang[:2])
			self.translated_text = out.text
			self.translated_text = 'It works. Try it!'



Hello @Omar_M_K_Shehada

In which file did you place the python code?