Server Script
Server Script
Server Script
A Server Script lets you dynamically define a Python Script that is executed on the server on a document event or
API
Introduced in Version 12
2. Features
2.1 Enabling Server Script
Server script must be enabled via site_config.json
bench --site site1.local set-config server_script_enabled true
After Cancel
Before Delete
After Delete
Before Save Submitted Document)
After Save Submitted Document)
2.3 Security
Frappe Framework uses the RestrictedPython library to restrict access to methods available for server scripts. Only the safe
methods, listed below are available in server scripts
For allowed methods, see Script API
3. Examples
3.1 Change the value of a property before change
Script Type: Before Save
if "test" in doc.description:
doc.status = 'Closed'
https://frappeframework.com/docs/user/en/desk/scripting/server-script 2/3
10/23/2020 Server Script
3.4 API
Script Type: API
Method Name: test_method
frappe.response['message'] = "hello"
Request: /api/method/test_method
Script 2
my_key = run_script('script_1').get('my_key')
https://frappeframework.com/docs/user/en/desk/scripting/server-script 3/3