Creating a Custom Script from the Frappe GUI
Frappe provides a convenient way to create and manage custom scripts directly from the GUI. Here's how you can create a custom script for Moodle integration:
1. Access the Server Scripts from the Build menu:
- Click on Server Script.
2. Create a New Script:
- Click the Add Server Script button to create a new script.
- You may get a message stating you need to enable this feature. If you do you may review the documentation by clicking on the link provided. If you do see this message you may continue to the next step.
- Give your script a meaningful name (for example,
custom_moodle_api). - Choose the proper Script Type.
- Choose the appropriate Document Type (if applicable).
- Choose the appropriate DocType Event.
3. Write the Script Code:
- Paste the following code into the script editor:
from frappe import call
def get_moodle_students(moodle_url, token):
# ... your Moodle API call logic ...
return students
Use code with caution.
4. Save and Execute:
- Click the Save button to save the script.
- To execute the script, click the Run button. You can provide the necessary arguments (Moodle URL and token) in the dialog box.
Using the Custom Script in Frappe:
Once you've created the custom script, you can call it from other parts of your Frappe application using frappe.call. For example, you could create a custom button in a DocType and call the script from its action handler:
@frappe.whitelist()
def synchronize_students(self):
# Get Moodle settings
settings = frappe.get_doc("Moodle API Settings", "Moodle API Settings")
moodle_url = settings.moodle_url
token = settings.token
# Call the custom script
students = call("custom_script.get_moodle_students", args=[moodle_url, token])
# Process the students data
# ...
Use code with caution.
← Previous
Building Print Format Templates with Frappe
Next →
Frappe Framework | Creating Custom Link Fields
Was this article helpful?