How to use whitelisted function in ServerSide Script Doctype

Hello Friends,
I am trying to create a lead custom doctype with an action button. I wrote the js script for the button in the clientside doctype and used tried to fetch out the code which I wrote in serverside script doctype using @frappe.whitelist() but I m not able to fetch it. But if I write the same thing in the py. file it works but that I can’t be done in a live instance…

Thanks In Advance

Share your client and server scripts, so others can help you.

This way I created a button in the clientside script doctype

This way I wrote whitelist code in the serverside script doctype

If you want the script to be run for ‘guest’ accounts(without login), you can set the “Allow Guest” checkbox in the server script.
I am not certain if the decorator @frappe.whitelist() is allowed to be used within the server script.

Thank you for your reply but the issue is I wanted to write frappe. whitelist() code as required… moreover, it’s a production server I can’t change the code so any idea where I can write whitelist code?

You should write an API in sever script and call from your js file.

That is true but to call the python whitelist function we need to use frappe. call() and for that, we need to give a method which is the location of the python file but the issue is I m writing python code in serverside script doctype from the frontside form so how can I give a method(Location) of that form in the client-side script doctype from frontside form to fetch that python function?

Try to look:
API Server Script

I tried it’s working thank you so much but one more question is if I wanted to send some variables from the javascript to python for the usage… how it can be done in API Script? I tried to give variables in args in a but I m not able to fetch it in my python

You can get them in frappe.form_dict
    method: "method",
    args: {
        x: 7,

you can get them from

  • frappe.form_dict["x"] raising KeyError if there is no x in args
  • or frappe.form_dict.x returning None if there is no x in args

and there is examples downside in Server Script

Thank You Its Working