ERPNext.com Frappe Cloud Support Partners Foundation Frappe School

Server and Client script args

I am trying to use the new options for server script in version 12.
I do not want to modify the .py files.
here is my code:
Python Server script:
Script Type: API
API Method: Print
Script:
def Print(m):
“console.log(m)”
frappe.response[‘message’] = m
JS Client Script:
frappe.call({
method: “Print”,
args: {
m : “test”
},
callback: ®=> {
var m2 = r.message;
console.log(m2);
m2 = m2.toString();
frappe.msgprint(m2);
}
});

I get undefined in the console!.
Any suggestions pls.

I’m having a hard time reading your code because it’s not formatted (try using code fences ```), but did you see the instructions on the Server Script page?

# respond to API

if frappe.form_dict.message == "ping":
	frappe.response['message'] = "pong"
else:
	frappe.response['message'] = "ok"

API call args are available in the frappe.form_dict variable.

Thanks for your reply and Sorry for giving you some hard time.
now I modified my code to:

Python Server script:
Script Type: API
API Method: Print

Script:     
`           frappe.response['message'] = frappe.form_dict.message`
Client Script:
frappe.call({
       		method: "Print",
        		args: {
        		    m : "test"
        		},
        		callback: (r)=> {
        		var m2 = r.message;
        		console.log(m2);
        		}
	        });

Now I get

null

Your argument names don’t match. You’re passing the argument m but then you reference frappe.form_dict.message.

Thanks very much for your support
It worked

1 Like